-
- /* An hung up descriptor does not increase the return value! */
- if (avail == 0)
- pfd[i].revents |= POLLHUP;
- else if (avail == -1)
- pfd[i].revents |= POLLERR;
- else
- happened |= POLLIN | POLLRDNORM;
- }
-
- if (FD_ISSET (pfd[i].fd, &wfds))
- happened |= POLLOUT | POLLWRNORM | POLLWRBAND;
-
- if (FD_ISSET (pfd[i].fd, &efds))
- happened |= POLLPRI | POLLRDBAND;
-
- pfd[i].revents |= pfd[i].events & happened;
- rc += (happened > 0);
- }
- }
+ if (r == 0)
+ happened |= POLLHUP;
+
+ /* If the event happened on an unconnected server socket,
+ that's fine. */
+ else if (r > 0 || ( /* (r == -1) && */ errno == ENOTCONN))
+ happened |= (POLLIN | POLLRDNORM) & sought;
+
+ /* Distinguish hung-up sockets from other errors. */
+ else if (errno == ESHUTDOWN || errno == ECONNRESET
+ || errno == ECONNABORTED || errno == ENETRESET)
+ happened |= POLLHUP;
+
+ else
+ happened |= POLLERR;
+ }
+
+ if (FD_ISSET (pfd[i].fd, &wfds))
+ happened |= (POLLOUT | POLLWRNORM | POLLWRBAND) & sought;
+
+ if (FD_ISSET (pfd[i].fd, &efds))
+ happened |= (POLLPRI | POLLRDBAND) & sought;
+
+ if (happened)
+ {
+ pfd[i].revents = happened;
+ rc++;
+ }
+ }