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

Fwd: [Libevent-users] Closing bufferevents sockets from the server side



Hey,
I understand Simon's view on how not to close buffer event sockets, but can some one explain why this  https://gist.github.com/714606 idea is bad?

---------- Forwarded message ----------
From: Sid <itissid@xxxxxxxxx>
Date: Wed, Nov 24, 2010 at 4:10 PM
Subject: Re: [Libevent-users] Closing bufferevents sockets from the server side
To: Simon Perreault <simon.perreault@xxxxxxxxxxx>


Just to clarify, what I am looking to do is free the buffer event by comparing the number of bytes deleted from evbuffer_cb_info to the actual argument sent in the args field Here: https://gist.github.com/714606 is an example function of what I am trying to do...

On Wed, Nov 24, 2010 at 4:03 PM, Sid <itissid@xxxxxxxxx> wrote:
Hmm right... But can you explain why is that wrong?


On Wed, Nov 24, 2010 at 2:02 PM, Simon Perreault <simon.perreault@xxxxxxxxxxx> wrote:
On 2010-11-24 15:54, Sid wrote:
> Well water marks seem to be the way to go.. But before your reply came I
> saw that in the library there is an interface
>
> *struct* evbuffer_cb_info {
>         size_t orig_size;
>         size_t n_added;
>         size_t n_deleted;
> };
>
> *typedef* *void* (*evbuffer_cb_func)(*struct* evbuffer *buffer,
>     *const* *struct* evbuffer_cb_info *info, *void* *arg);
>
> described http://www.wangafu.net/~nickm/libevent-book/Ref7_evbuffer.html
>
>
> I think this is the right way to do this stuff...

It is most definitely the *wrong* way.

Free the bufferevent in write callback with a write watermark set to 0.
That is the right way to do it.

Simon
--
DTN made easy, lean, and smart --> http://postellation.viagenie.ca
NAT64/DNS64 open-source        --> http://ecdysis.viagenie.ca
STUN/TURN server               --> http://numb.viagenie.ca