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.
This commit is contained in:
Willy Tarreau 2017-03-13 20:36:48 +01:00
parent dd437d9a4c
commit 19c4ab97c1

View 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;