If I do the following
- invoke event_add for a particular file descriptor fd1 and timeout t1 = 5 seconds
- after 1 second, without waiting for any event to occur, I call event_add again for f1 and t1 = 5 seconds.
Will the second invocation of event_add cancel the earlier call? i.e. if the event does not happen, will the timeout now happen at 6 seconds instead of 5 seconds? Or, will we have 2 timeouts - one at 5 and another at 6 seconds
Does this behaviour differ between libevent versions 1 and 2? I did not find any documentation pertaining to this. I’m not able to comprehend this is from a reading of the code. I can obviously write a program to test this out but since the program has to work on different platforms, it would be better if there is a concrete documentation that describes the behaviour under these conditions.
Quoting the official documentation (Making events pending and non-pending section):
So you could expect the event being triggered for timeout after 6 seconds. Of course, any event occuring on the event structure (if associated with a file descriptor for example) between the two calls to
event_add()
will also reset the timer.However, extending the answer with a non-asked piece of advice, pay attention to the following part:
Thus if you want to delete the timeout on an existing event, you could choose between:
event_add()
directly with a non-NULL
timeout set to{0, 0}
event_del()
/event_add()
, having set aNULL
timeout this timeI would recommend the latter.