]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: kqueue: take care of EV_EOF to improve polling status accuracy
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Mar 2017 19:36:48 +0000 (20:36 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 Mar 2017 15:35:17 +0000 (16:35 +0100)
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.

src/ev_kqueue.c

index e6338e6973f13030c7126a5c13f4e2041454e454..6f41c731f435b904016fc83628e8a31eb3772838 100644 (file)
@@ -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;