poll(2): Set POLLERR properly
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 25 Sep 2011 14:19:19 +0000 (22:19 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 25 Sep 2011 14:21:40 +0000 (22:21 +0800)
If the other side closed the connection and error happens (so_error != 0)
POLLERR is turned on accordingly.

sys/kern/sys_generic.c

index 42cbc3b..793e2fc 100644 (file)
@@ -1383,6 +1383,9 @@ poll_copyout(void *arg, struct kevent *kevp, int count, int *res)
                                if (kevp[i].flags & EV_NODATA)
                                        pfd->revents |= POLLHUP;
 #endif
+                               if ((kevp[i].flags & EV_EOF) &&
+                                   kevp[i].fflags != 0)
+                                       pfd->revents |= POLLERR;
                                if (pfd->events & POLLIN)
                                        pfd->revents |= POLLIN;
                                if (pfd->events & POLLRDNORM)
@@ -1397,8 +1400,10 @@ poll_copyout(void *arg, struct kevent *kevp, int count, int *res)
                                 * In this case a disconnect is implied even
                                 * for a half-closed (write side) situation.
                                 */
-                               if (kevp[i].flags & EV_NODATA) {
+                               if (kevp[i].flags & EV_EOF) {
                                        pfd->revents |= POLLHUP;
+                                       if (kevp[i].fflags != 0)
+                                               pfd->revents |= POLLERR;
                                } else {
                                        if (pfd->events & POLLOUT)
                                                pfd->revents |= POLLOUT;