From aa622c3d0448dbcf9cad62ea40234b9b01173663 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Sun, 25 Sep 2011 22:19:19 +0800 Subject: [PATCH] poll(2): Set POLLERR properly If the other side closed the connection and error happens (so_error != 0) POLLERR is turned on accordingly. --- sys/kern/sys_generic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 42cbc3bf0d..793e2fc00c 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -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; -- 2.41.0