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

RE: [Libevent-users] Some questions. 1- Releasing bufferevents. 2 - Timeouts on bufferevents.



Thanks for the assistance.

-----Original Message-----
From: owner-libevent-users@xxxxxxxxxxxxx [mailto:owner-libevent-users@xxxxxxxxxxxxx] On Behalf Of Mark Ellzey
Sent: Tuesday, August 13, 2013 2:56 PM
To: libevent-users@xxxxxxxxxxxxx
Subject: Re: [Libevent-users] Some questions. 1- Releasing bufferevents. 2 - Timeouts on bufferevents.

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 majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.