From owner-freebsd-net@FreeBSD.ORG Fri Sep 2 21:09:35 2011 Return-Path: Delivered-To: freebsd-net@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4F9F2106564A; Fri, 2 Sep 2011 21:09:35 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 61C568FC0C; Fri, 2 Sep 2011 21:09:33 +0000 (UTC) Received: from porto.starpoint.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id AAA23623; Sat, 03 Sep 2011 00:09:21 +0300 (EEST) (envelope-from avg@FreeBSD.org) Received: from localhost ([127.0.0.1]) by porto.starpoint.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1QzazI-000Ezc-UR; Sat, 03 Sep 2011 00:09:20 +0300 Message-ID: <4E6145FF.3090803@FreeBSD.org> Date: Sat, 03 Sep 2011 00:09:19 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0.1) Gecko/20110901 Thunderbird/6.0.1 MIME-Version: 1.0 To: Bruce Evans References: <4E60A1B8.7080607@FreeBSD.org> <20110902104018.GA12845@stack.nl> <20110903015445.J957@besplex.bde.org> <4E6123F4.4010209@FreeBSD.org> <20110903053813.V2093@besplex.bde.org> In-Reply-To: <20110903053813.V2093@besplex.bde.org> X-Enigmail-Version: undefined Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-net@FreeBSD.org, freebsd-standards@FreeBSD.org, Jilles Tjoelker Subject: Re: POLLHUP on never connected socket X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Sep 2011 21:09:35 -0000 on 02/09/2011 23:26 Bruce Evans said the following: > Yes, that's what I'm asking. It should be simpler to fix if it is just > a bug and doesn't involve reader/writer races. The code for setting > POLLHUP for sockets is simple: from uipc_socket.c: > > % if ((events & POLLINIGNEOF) == 0) { > % if (so->so_rcv.sb_state & SBS_CANTRCVMORE) { > % revents |= events & (POLLIN | POLLRDNORM); > % if (so->so_snd.sb_state & SBS_CANTSENDMORE) > % revents |= POLLHUP; > % } > % } > > So POLLHUP tracks SBS_CANTRCVMORE && SBS_CANTSENDMORE exactly, and POLLHUP > is never set without POLLIN. Umm, it seems that when you say that then you are assuming that the events contain POLLIN. In what I observe events == POLLOUT | POLLPRI and thus only POLLHUP is set in the revents. Not that this means too much, just an observation. > But in my version: > > % if ((events & POLLINIGNEOF) == 0) { > % if (so->so_rcv.sb_state & SBS_CANTRCVMORE) { > % if (so->so_snd.sb_state & SBS_CANTSENDMORE) > % revents |= POLLHUP; > % else > % revents |= events & (POLLIN | POLLRDNORM); > % } > % } > > POLLIN is not set by hangup, bit actually means that there is (non-null) > input available. jilles referred to this bug in -current. -- Andriy Gapon