[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] async writes for bufferevent_write/bufferevent_write_buffer?
On Thu, Jul 18, 2013 at 11:57:32AM -0500, Mark Ellzey wrote:
> On Thu, Jul 18, 2013 at 10:52:06AM -0600, J. Scott Dorr wrote:
> >
> > On Jul 18, 2013, at 9:59 AM, Mark Ellzey <mthomas@xxxxxxxxxx> wrote:
> > >
> > > A little about deferred callbacks:
> > >
> > > When you do something like bufferevent_write(), the actual underlying
> > > protocol write is not executed immediately; it is queued up to be run in
> > > the next iteration of the event loop. So if you do a sleep() in your
> > > callback, you will not drop back to the main loop until you return.
> > > Though even without the sleep, the write will not be done until the next
> > > loop.
> >
> > This was my expectation, but the fact that the client sees the echo'd hello before the sleep() finishes strongly suggests that the write is happening before going back to the event loop.
> > The sleep() is only there to help me visualize the flow and the order in which things take place.
> >
>
> Wait, so you see the write being done immediately? How is this not
> async?
>
I think I see your confusion here. You are assuming that with async IO
that a send() will not immediately send data. This is not the case. If
data can be written, it will write. Otherwise send() will return EAGAIN,
informing the event handler to try the write again.
Since you are testing over loopback with small payloads, you never hit
that condition.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.