[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] How to close bufferevent connection?
- To: libevent-users@xxxxxxxxxxxxx
- Subject: Re: [Libevent-users] How to close bufferevent connection?
- From: Nick Mathewson <nickm@xxxxxxxxxxxxx>
- Date: Thu, 3 Jun 2010 14:42:47 -0400
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Thu, 03 Jun 2010 14:42:53 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:content-type:content-transfer-encoding; bh=pga+fZHHbnj02aLEnGgwR/PwgSU8i/AocBh2HHiZPZM=; b=roHnRntY2vHDCVlnSKVK7Hg70pJ+6VYDWInJ34PMeQiluNc1MZHWg2nFMUIMiDQ7hF 9h6vJ3WlnU3iheBDf+tR6Yif8iBaiVu/xvpmAKrYjJyQygW0nGsZkifqugLRo4FzgOy+ xv3xZVaqTJdLAmcSw0zarElGzNt424jFd57dU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=qzCJJ0lnLbZJAGvEUelR3gieKGkLn8QPZVYmNF5mQdDGQ9X0zev+rjRxLNNALYjUE3 39JEhuvuKW3rTmW8p6aKhzFRgo8xuYDECy9iKWKP23JpF9sVx1KQSfuRL6zFo/ZFye2Z NEph0EYJ+guiHhqxJb2QdJgddBjBtaph4jcXg=
- In-reply-to: <1275361633.18210.2.camel@simson>
- References: <1275361633.18210.2.camel@simson>
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
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.