On Fri, Aug 09, 2013 at 11:55:54AM +0000, Tomer Heber wrote:
> 
> 1. When using bufferevents I pass a class/struct as a "ctx/opaque"  for each 
> bufferevent.
> From the book:
> "Bufferevents are internally reference-counted, so if the bufferevent has 
> pending deferred callbacks when you free it, it won't be deleted until the 
> callbacks are done."
> 
> In my code I do the following:
> bufferevent_free(bev);
> delete ctx;
> 
> What worries my is the following scenario:
> I call bufferevent_free and release the ctx as well. But since the 
> bufferevent has some pending events a callback will be called and the ctx 
> will be invalid (since it was already released when I invoked the delete 
> command).
> 
> I was considering doing the following
> 
> bufferevent_setcb(bev, NULL, NULL, NULL, NULL);
> 
> bufferevent_free(bev);
> delete ctx;
> 
> Will it work?
> 

That would work fine.

> bufferevent_set_timeouts(bev, NULL, {20, 0})

The read timeout is infinite, the write timeout is 20 seconds.


> 
> Is it valid? The timeout will only be set for write?
> 
> 

Yes.

> D) From the book:
> 
> "When a read or write timeout occurs, the corresponding read or write 
> operation becomes disabled on the bufferevent. The event callback is then 
> invoked with either BEV_EVENT_TIMEOUT|BEV_EVENT_READING or 
> BEV_EVENT_TIMEOUT|BEV_EVENT_WRITING."
> 
> 
> Is it ok to re-enable the buffevent.
> 
> E.g.  EV_EVENT_TIMEOUT|BEV_EVENT_READING event was invoked.
> 
> So I execute:
> 
>  bufferevent_enable(bev, EV_READ) It is okay?
> 

Yes, in-fact you have to (if you want to in-fact keepr eading). an event type of
EV_READ|EV_TIMEOUT will disable the read-side of the bev before passing to your 
eventcb.

> 
> Sorry for all these questions... I just don't want to do mistakes/bad design 
> decisions without fully understanding how libevent works.
> 
> 
> Thanks in advance,
> 
> Tomer.
> 
> 
***********************************************************************
To unsubscribe, send an e-mail to [email protected] with
unsubscribe libevent-users    in the body.

Reply via email to