From: Willy Tarreau Date: Mon, 13 Mar 2017 19:36:48 +0000 (+0100) Subject: MEDIUM: kqueue: take care of EV_EOF to improve polling status accuracy X-Git-Tag: v1.8-dev1~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19c4ab97c10b75b69d02bf7ebb6c2c3331d7bd83;p=thirdparty%2Fhaproxy.git MEDIUM: kqueue: take care of EV_EOF to improve polling status accuracy kevent() always sets EV_EOF with EVFILT_READ to notify of a read shutdown and EV_EOF with EVFILT_WRITE to notify of a write error. Let's check this flag to properly update the FD's polled status (FD_POLL_HUP and FD_POLL_ERR respectively). It's worth noting that this one can be coupled with a regular read event to notify about a pending read followed by a shutdown, but for now we only use this to set the relevant flags (HUP and ERR). The poller now exhibits the flag HAP_POLL_F_RDHUP to indicate this new capability. An improvement may consist in not setting FD_POLL_IN when the "data" field is null since it normally only reflects the amount of pending data. --- diff --git a/src/ev_kqueue.c b/src/ev_kqueue.c index e6338e6973..6f41c731f4 100644 --- a/src/ev_kqueue.c +++ b/src/ev_kqueue.c @@ -126,9 +126,13 @@ REGPRM2 static void _do_poll(struct poller *p, int exp) if (kev[count].filter == EVFILT_READ) { fdtab[fd].ev |= FD_POLL_IN; + if (kev[count].flags & EV_EOF) + fdtab[fd].ev |= FD_POLL_HUP; } else if (kev[count].filter == EVFILT_WRITE) { fdtab[fd].ev |= FD_POLL_OUT; + if (kev[count].flags & EV_EOF) + fdtab[fd].ev |= FD_POLL_ERR; } if (fdtab[fd].ev & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR)) @@ -232,7 +236,7 @@ static void _do_register(void) p->name = "kqueue"; p->pref = 300; - p->flags = 0; + p->flags = HAP_POLL_F_RDHUP; p->private = NULL; p->clo = NULL;