Hi,
I am working on a socket programming code and I need to modify part of it. In the code there is a line where a process receives a message :
receive(source, buf);
When a process receives a message, I don't want to deliver the message immediately, what I want is to deliver it at sometime later (with some delay).
do you know how I can do it? I tried the sleep() but it is not what I want, since when the process is asleep,it does not receive next messages until sleep time is elapsed. I think I should use timers, like start a timer when a message is received, and after the timer is expired I deliver the message, and I need to start a timer for each message. I don't know how to do this and which timers I should use. I f anybody can explain this to me, it will be a great help!
if a resolution of seconds suffice you may use 'time()' for the timestamp.
This is one way to do it:
You need a a list that holds the data and timestamp (current time + delay time) (like struct TimedData { timestamp; data; };)
When someone wants the data he has to iterate through the list and take the data that is expired
After the set number of seconds you program will receive a SIGALARM signal and if you have written a
signal handler then it will jump there, run that bit of code, and then return to where it was.
In the SIGALARM handler your program delivers the message