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

Re: [Libevent-users] How to close bufferevent connection?



On Mon, May 31, 2010 at 11:07 PM, Felix Nawothnig
<felix.nawothnig@xxxxxxxxxxxxxx> wrote:
> Hey.
>
> What's the "suggested" way to close a bufferevent connection?
>
> Currently I do:
>
>        fd = bufferevent_getfd(bev);
>        evutil_closesocket(fd);
>
> ... followed by a manual:
>
>        my_event_handler(bev, BEV_EVENT_EOF, NULL);
>
> ... because it doesn't seem to be called otherwise.
>
> Is this the "correct" way? Is the fact that the event handler not called
> a bug?
>

Two points to expand on hcpark's reply:

1) Calling bufferevent_free() will only close the socket if the
bufferevent was set up with the BEV_OPT_CLOSE_ON_FREE option.  [I
already mentioned this to Felix on Sourceforge, but it's good to keep
in mind.  The default behavior by analogy with event_del and
event_free, neither of which close their underlying fd.]

2)  The BEV_EVENT_EOF event is only generated for an EOF that you
*receive*, not when you close the socket yourself.  Since most
backends (select, poll, etc) don't provide a notice when *you* close
an fd, there's no event generated for that on the bufferevent.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.