diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index 378903a627..d99d6e1b83 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -191,7 +191,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { revents = 0; if (ev->filter == EVFILT_READ) { - if (w->events & UV__POLLIN) { + if (w->pevents & UV__POLLIN) { revents |= UV__POLLIN; w->rcount = ev->data; } else { @@ -205,7 +205,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { } if (ev->filter == EVFILT_WRITE) { - if (w->events & UV__POLLOUT) { + if (w->pevents & UV__POLLOUT) { revents |= UV__POLLOUT; w->wcount = ev->data; } else { diff --git a/src/unix/linux-core.c b/src/unix/linux-core.c index e4c34a1808..cb6df78983 100644 --- a/src/unix/linux-core.c +++ b/src/unix/linux-core.c @@ -105,6 +105,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { uv__io_t* w; uint64_t base; uint64_t diff; + unsigned int masked_events; int nevents; int count; int nfds; @@ -208,7 +209,15 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { continue; } - w->cb(loop, w, pe->events); + /* + * Give users only events they're interested in. Prevents spurious + * callbacks when previous callback invocation in this loop has stopped + * the current watcher. Also, filters out events that users has not + * requested us to watch. + */ + masked_events = pe->events & w->pevents; + if (masked_events != 0) + w->cb(loop, w, masked_events); nevents++; }