From: Jamie Lokier <jamie@shareable.org>
To: Davide Libenzi <davidel@xmailserver.org>
Cc: Ben Mansell <ben@zeus.com>, Steven Dake <sdake@mvista.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Is POLLHUP an input-only or bidirectional condition? (was: epoll reporting events when it hasn't been asked to)
Date: Fri, 2 Apr 2004 19:40:35 +0100 [thread overview]
Message-ID: <20040402184035.GA653@mail.shareable.org> (raw)
In-Reply-To: <Pine.LNX.4.44.0404020717350.1828-100000@bigblue.dev.mdolabs.com>
[New thread because I want people who understand POLLHUP to clarify.
The parent thread's question was: why does epoll always report POLLHUP
and POLLERR conditions even when the program didn't ask for those.
The trivial answer is because that's what poll() does.]
Davide Libenzi wrote:
> Handling by, for example, removing the fd from the epoll set and
> unregistering/freeing the associated data structures. IMO we can leave the
> current behaviour, but if someone sees huge problems with this, the fix is
> a one-liner.
None of select, poll or epoll allow a program to ignore POLLERR while
checking POLLIN or POLLOUT. So at least epoll is consistent with the
other two.
It is possible to ignore POLLHUP conditions with select(), but not
poll() or epoll. For sockets at least, POLLHUP should indicate the
socket is fully closed, so that reading and writing will both fail.
Thus it makes sense that POLLHUP is not ignorable, although curiously
select() only treats POLLHUP as an _input_ condition, so it won't wake
something that's waiting only for output readiness. poll() will
always wake even if you're only waiting for POLLOUT.
POLLERR is set by UDP sockets with a pending error condition, and that
will be reported whether you read or write to the socket (except in
some perverse conditions where MSG_MORE has been used - then app state
machines could get confused). So it's appropriate for a POLLIN or
POLLOUT waiter to be woken when there's a POLLERR condition.
Summary: epoll is consistent with poll(). I'm not sure why poll() and
select() treat POLLHUP differnently. A poll() for POLLOUT will be
woken by a POLLHUP condition, yet a select() for output will _not_ be
woken by a POLLHUP condition.
Perhaps that indicates some confusion over what POLLHUP is supposed to
mean, and when it should be set by devices and/or sockets: is it for
input hangup conditions that allow further output, or for total hangup
conditions where input and output are both guaranteed to fail?
If it's the latter, as it seems to be for sockets, then the poll() and
epoll behaviour makes sense, but select() doesn't. If it's the
former, then the select() behaviour is the only one that makes sense.
Hence my question: does anyone know for sure which POLLHUP behaviour
is correct and sensible?
-- Jamie
next prev parent reply other threads:[~2004-04-02 18:40 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-01 18:25 epoll reporting events when it hasn't been asked to Ben Mansell
2004-04-01 19:28 ` Davide Libenzi
2004-04-01 23:29 ` Steven Dake
2004-04-02 9:04 ` Ben Mansell
2004-04-02 15:22 ` Davide Libenzi
2004-04-02 18:40 ` Jamie Lokier [this message]
2004-04-03 12:19 ` Is POLLHUP an input-only or bidirectional condition? Richard Kettlewell
2004-04-03 21:44 ` Is POLLHUP an input-only or bidirectional condition? (was: epoll reporting events when it hasn't been asked to) Davide Libenzi
2004-04-03 22:35 ` Jamie Lokier
2004-04-04 1:28 ` Davide Libenzi
2004-04-04 2:08 ` Jamie Lokier
2004-04-04 2:49 ` Davide Libenzi
2004-04-04 18:51 ` Ben Mansell
2004-04-04 19:41 ` Davide Libenzi
2004-04-04 20:24 ` Jamie Lokier
2004-04-14 17:59 ` epoll reporting events when it hasn't been asked to Dirk Morris
2004-04-14 19:39 ` Jamie Lokier
2004-04-14 20:21 ` Dirk Morris
2004-04-14 21:48 ` Jamie Lokier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040402184035.GA653@mail.shareable.org \
--to=jamie@shareable.org \
--cc=ben@zeus.com \
--cc=davidel@xmailserver.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sdake@mvista.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox