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

Re: [Libevent-users] how to flush output immediately?



Hi!

On Wed, Mar 24, 2010 at 11:27:26PM +0800, Shuo Chen wrote:
>On Wed, Mar 24, 2010 at 11:24 PM, Jarod Liu <liuyuanzhi@xxxxxxxxx> wrote:
>> I want to implement a server which listen on a port. When new
>> connection come, write out something, then close the connection.
>> I try use bufferevent_write put data to output buffer then
>> bufferevent_free, but I found the connection close without flush
>> output first.

>Pls google SO_LINGER.

Not a good idea in my eyes.

I had my event based stuff have a callback when I send something and the
sent data was all written to the socket. Then I closed the socket *in
that callback*, so the data wasn't lost (which it was when I closed
while the data was still in buffers, waiting for the writable callback
to fire). In addition, I had my code try writing (non-blocking) until
I hit EAGAIN or EWOULDBLOCK (unless there's already data in the
send buffers), which could save iterations through the main loop in many
cases. Continued to work when I switched to libevent (but only used
the basic event loop, not bufferevent; main aim was to leverage
kqueue/epoll instead of select; I had own C++ based higher level stuff
above the mainloop).

Kind regards,

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