From owner-freebsd-net@FreeBSD.ORG Fri Sep 2 09:46:18 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 55642106564A; Fri, 2 Sep 2011 09:46:18 +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 6B0908FC12; Fri, 2 Sep 2011 09:46:17 +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 MAA16779; Fri, 02 Sep 2011 12:28:25 +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 1QzQ2z-000EZt-6m; Fri, 02 Sep 2011 12:28:25 +0300 Message-ID: <4E60A1B8.7080607@FreeBSD.org> Date: Fri, 02 Sep 2011 12:28:24 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110830 Thunderbird/6.0 MIME-Version: 1.0 To: freebsd-net@FreeBSD.org, freebsd-standards@FreeBSD.org X-Enigmail-Version: undefined Content-Type: text/plain; charset=X-VIET-VPS Content-Transfer-Encoding: 7bit Cc: Subject: 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 09:46:18 -0000 I see a problem where FreeBSD kernel (recent head) returns POLLHUP _alone_ (0x10) for a socket that has never been connected - a client socket for which connect(2) failed. There is also a piece of software that doesn't expect that flag and exhibits illogical behavior because of it. This is how POSIX describes POLLHUP: POLLHUP The device has been disconnected. This event and POLLOUT are mutually-exclusive; a stream can never be writable if a hangup has occurred. However, this event and POLLIN, POLLRDNORM, POLLRDBAND, or POLLPRI are not mutually-exclusive. This flag is only valid in the revents bitmask; it shall be ignored in the events member. For me "disconnected" _implies_ that the device should have been connected first. But this is not explicitly said anywhere. Also, I think it's possible that a socket gets connected and immediately disconnected (before poll(2) is called), then the POLLHUP would be appropriate in any interpretation. So, I am inclined to think that the software should check for POLLHUP. But I would like to ask your opinion since the problem appears to be FreeBSD-specific. -- Andriy Gapon