POLLHUP on never connected socket

Andriy Gapon avg at FreeBSD.org
Fri Sep 2 21:09:35 UTC 2011


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


More information about the freebsd-standards mailing list