Editing POLLHUP polling

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 27: Line 27:
The only talk of this issue I've found online is the 2001 email "[https://groups.google.com/g/comp.unix.programmer/c/bNNadBIEpTo/m/G5gs1mqNhbIJ poll() and events==0]" which has no clear answers.
The only talk of this issue I've found online is the 2001 email "[https://groups.google.com/g/comp.unix.programmer/c/bNNadBIEpTo/m/G5gs1mqNhbIJ poll() and events==0]" which has no clear answers.


== Existing lore ==
== General POLLHUP lore ==


Richard Kettlewell's [https://www.greenend.org.uk/rjk/tech/poll.html poll() and EOF] has a test results for the case of setting POLLIN and closing a socket with no data to read. This is the most common case of POLLHUP use I see online.


The test results give us some interesting data:
Richard Kettlewell's [https://www.greenend.org.uk/rjk/tech/poll.html poll() and EOF] page has some interesting  


* The first is that POLLIN is often set if a socket is closed. If set alone this means a POLLIN poll without any return events may mean you still can't read from the socket
- events = POLLIN
* The second is that POLLHUP is often not set on older systems. This means programs polling POLLOUT may miss socket closures altogether. This is one reason why systems are moving to set POLLHUP instead of just POLLIN
* The third is that neither are always set. Cygwin and very early Linux systems only set POLLHUP. This seems like a bug to me especially as most online advice recommend watching POLLIN for socket closures when writing portable programs


This data doesn't check what poll returns if there's still data in the socket to read but the connection has closed. That case may have entirely different results.
- doesn't write to the socket first


Another issue is what to return if a socket was never connected in the first place?


* [https://jira.mongodb.org/browse/CDRIVER-2996 AIX returned POLLOUT in 2019]
- may indicate with POLLIN
* [https://freebsd-net.freebsd.narkive.com/zJxZYQdq/pollhup-on-never-connected-socket FreeBSD returned POLLHUP in 2011]
 
- may indicate with POLLHUP
 
- may indicate with BOTH
 
- On socket disconnection, POLLIN set in poll()->revents and recv() returning 0 is the only portable and reliable method.
 
https://www.illumos.org/issues/4627 not generating POLLHUP dangers
 
https://github.com/illumos/illumos-gate/commit/68846fd00135fb0b10944e7806025cbefcfd6546
 
- stuff to read still in socket
 
- may indicate with POLLOUT if the socket has failed to connect in the first place
 
<nowiki>https://lkml.iu.edu/hypermail/linux/kernel/0605.1/1420.html</nowiki>
 
https://jira.mongodb.org/browse/CDRIVER-2996 POLLOUT<nowiki/>https://lists.freebsd.org/pipermail/freebsd-net/2011-September/029712.html
 
freebsd different ideas
 
 
POLLIN but no data, only POLLHUP <nowiki>https://sourceware.org/bugzilla/show_bug.cgi?id=13660</nowiki>
 
 
<nowiki>https://developer.illumos.narkive.com/dUe1v0Ya/poll-not-returning-pollhup-for-tcp-sockets-closed-by-the-other-end</nowiki> "ie you get POLLIN with a zero length read(). SO_KEEPALIVE won't be involved. Now if you down the network interface you should eventually get the POLLHUP."
 
<nowiki>https://bugs.dragonflybsd.org/issues/3268</nowiki> pipes don't do POLLHUP BUG


== Test code ==
== Test code ==
Please note that all contributions to JookWiki are considered to be released under the Creative Commons Zero (Public Domain) (see JookWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)