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

Re: [Libevent-users] draining bufferevents internal buffer



On Fri, Sep 21, 2012 at 09:25:43PM +0200, Julian Scheel wrote:
> Hi,
> 
> I wonder if there is a way to drain the internal buffer of a bufferevent? Actually I use a bufferevent to write data into a socket. But it can happen that the socket is not accepting data for a while, which obviously lets the bufferevents internal buffer grow. Now I'd like to set a maximum buffer size, so that I can ensure that even when the socket is blocked for a longer period the application won't eat up all available memory.
> I tried to do a evbuffer_drain on the evbuffer returned by bufferevent_get_output(), but this simply seems to have no effect. The buffer size remains unchanged, no matter how many bytes I try to drain out.
> Is there any way to achieve what I want to do with libevent?


When you call evbuffer_drain() it doesn't free() resources, it basically
just resets the pointer back to the start of the buffer.

It sounds like you may want to keep a seperate evbuffer you allocate
yourself, if something actually needs the data you can call
bufferevent_write_buffer(bev, yourevbuffer). Otherwise you can keep
track of how big it is, and if it gets too big for you, call
evbuffer_free() and immediately allocate a new one. 
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.