From 8c317b22318df63736f829347b5022eef1bcd9f1 Mon Sep 17 00:00:00 2001 From: logwang Date: Mon, 27 Nov 2017 18:39:34 +0800 Subject: [PATCH] Fix #107: some invalid usages of kqueue in `ff_epoll`. 1.Both EVFILT_READ and EVFILT_WRITE are values but not flags. It needs to check whether it is equal but not to do logic and. 2.If the read direction of the socket has shutdown, then the filter also sets EV_EOF in `flags`, and returns the socket error (if any) in `fflags`. --- lib/ff_epoll.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/ff_epoll.c b/lib/ff_epoll.c index d0e8d5a91..3e236b8bb 100644 --- a/lib/ff_epoll.c +++ b/lib/ff_epoll.c @@ -69,10 +69,11 @@ ff_event_to_epoll(void **ev, struct kevent *kev) unsigned int event_one = 0; struct epoll_event **ppev = (struct epoll_event **)ev; - if (kev->filter & EVFILT_READ) { - event_one |= EPOLLIN; - } - if (kev->filter & EVFILT_WRITE) { + if (kev->filter == EVFILT_READ) { + if (kev->data || !(kev->flags & EV_EOF)) { + event_one |= EPOLLIN; + } + } else if (kev->filter == EVFILT_WRITE) { event_one |= EPOLLOUT; } @@ -81,7 +82,17 @@ ff_event_to_epoll(void **ev, struct kevent *kev) } if (kev->flags & EV_EOF) { - event_one |= EPOLLIN; + event_one |= EPOLLHUP; + + if (kev->fflags) { + event_one |= EPOLLERR; + } + + if (kev->filter == EVFILT_READ) { + event_one |= EPOLLIN; + } else if (kev->filter == EVFILT_WRITE) { + event_one |= EPOLLERR; + } } (*ppev)->events = event_one;