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

Re: [Libevent-users] Why write event handler was trigged only once?



On Fri, Jul 5, 2013 at 2:06 AM, ééä <david.bangyi@xxxxxxxxx> wrote:
> Bufferevent is a little different from raw Event. Every bufferevent created
> via function bufferevent_socket_new() has been assigned EV_READ| EV_PERSIST
> and EV_WRITE | EV_PERSIST flags.
>
> struct bufferevent * bufferevent_socket_new(......){
> ..............
> event_assign(&bufev->ev_read, bufev->ev_base,fd, EV_READ | EV_PERSIST,
> bufferevent_readcb, bufev);
> event_assign(&bufev->ev_write, bufev->ev_base,fd,EV_WRITE| EV_PERSIST,
> bufferevent_writecb, bufev);
> ............
> }
>
> so my write callback will be called by function 'bufferevent_writecb' under
> some conditions.  I need know this 'conditions'.

The write callback is invoked when the bufferevent's output buffer
becomes "drained enough".  Usually, that means that some data was
written, and the output buffer is now empty.  You can make it so that
the write callback happens even on nonempty buffers by setting a write
low-watermark.

This is documented in
http://www.wangafu.net/~nickm/libevent-book/Ref6_bufferevent.html

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