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

Re: [Libevent-users] Question on paired buffer events



On Thu, Jun 30, 2011 at 1:53 PM, Ed Day <edday2006@xxxxxxxxx> wrote:
> In reading the documentation on paired buffer events, it says they can
> be used in "a networking program that needs to talk to itself".  That
> is exactly what I have and this capability sounds like what I need to
> implement an internal queue.  But the problem is these events do not
> seem to cause the event dispatch loop to block.  In my test program, I
> created a pair using bufferevent_pair_new and then set up a read
> callback on one event and a write on the other.  I then went into the
> event dispatch loop and immediately fell out the bottom.  Is this not
> the correct way to use these events?

Paired buffervents don't use any events internally, so they don't stop
the event loop from reaching its "no events pending" condition and
exiting.  If you really need to use paired bufferevents with no actual
events, the best workaround is probably, like Mark suggested, to add a
dummy timer event.  It doesn't need to be 5 seconds; it doesn't need
to do anything.

Arguably, paired bufferevents _should_ keep the event loop from
exiting.  If anyone's interested in fixing this in bufferevent_pair.c,
the way to go is probably to look at the internal functions
"event_base_add_virtual" and "event_base_del_virtual" in event.c.  A
"virtual" event serves no purpose other than to keep the event base
from exiting.  The rule to implement is probably something like, "Add
a virtual event whenever a paired bufferevent has reading enabled, or
whenever it has writing enabled and has data to write."

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