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`.
This commit is contained in:
logwang 2017-11-27 18:39:34 +08:00
parent e76966dcf1
commit 8c317b2231
1 changed files with 16 additions and 5 deletions

View File

@ -69,10 +69,11 @@ ff_event_to_epoll(void **ev, struct kevent *kev)
unsigned int event_one = 0; unsigned int event_one = 0;
struct epoll_event **ppev = (struct epoll_event **)ev; struct epoll_event **ppev = (struct epoll_event **)ev;
if (kev->filter & EVFILT_READ) { if (kev->filter == EVFILT_READ) {
event_one |= EPOLLIN; if (kev->data || !(kev->flags & EV_EOF)) {
} event_one |= EPOLLIN;
if (kev->filter & EVFILT_WRITE) { }
} else if (kev->filter == EVFILT_WRITE) {
event_one |= EPOLLOUT; event_one |= EPOLLOUT;
} }
@ -81,7 +82,17 @@ ff_event_to_epoll(void **ev, struct kevent *kev)
} }
if (kev->flags & EV_EOF) { 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; (*ppev)->events = event_one;