[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] event_del and already 'in-flight' event triggers



On Thu, Jul 5, 2012 at 3:34 PM, Scott Dorr <j.scott.dorr@xxxxxxxxx> wrote:
> When an event_del() is called on an evq, what happens to triggerings that
> were already 'in-flight' but haven't had their callbacks called yet.

event_del() will make an active event inactive; if its callback was
scheduled but has not been run, it won't be run.

>
> For example:
>
> read event R is active on fd 42, uses 'callback_func()' as its callback
> new packet P1 comes in on fd 42
> new packet P2 comes in on fd 42
> libevent calls callback_func() for P1
> callback_func() calls event_del() on event R

In this case, callback_func would not even be scheduled until the next
time around the event loop.

> What happens with P2?  Is callback_func() still going to be called for it?

Nope, not unless you call event_add() on R again.

The easiest pattern here is to try to drain your socket completely on
the callback.  Libevent doesn't promise you one callback per packet;
it promises you what you will get a callback so long as the socket is
active and readable.

hth,
-- 
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.