Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 02 Sep 2011 12:28:24 +0300
From:      Andriy Gapon <avg@FreeBSD.org>
To:        freebsd-net@FreeBSD.org, freebsd-standards@FreeBSD.org
Subject:   POLLHUP on never connected socket
Message-ID:  <4E60A1B8.7080607@FreeBSD.org>

next in thread | raw e-mail | index | archive | help

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4E60A1B8.7080607>