diff --git a/src/unix/core.c b/src/unix/core.c index d5992772..e5c9a4d9 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -603,14 +603,6 @@ void uv__io_init(uv__io_t* w, uv__io_cb cb, int fd) { } -/* Note that uv__io_start() and uv__io_stop() can't simply remove the watcher - * from the queue when the new event mask equals the old one. The event ports - * backend operates exclusively in single-shot mode and needs to rearm all fds - * before each call to port_getn(). It's up to the individual backends to - * filter out superfluous event mask modifications. - */ - - void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events) { assert(0 == (events & ~(UV__POLLIN | UV__POLLOUT))); assert(0 != events); @@ -620,6 +612,20 @@ void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events) { w->pevents |= events; maybe_resize(loop, w->fd + 1); +#if !defined(__sun) + /* The event ports backend needs to rearm all file descriptors on each and + * every tick of the event loop but the other backends allow us to + * short-circuit here if the event mask is unchanged. + */ + if (w->events == w->pevents) { + if (w->events == 0 && !ngx_queue_empty(&w->watcher_queue)) { + ngx_queue_remove(&w->watcher_queue); + ngx_queue_init(&w->watcher_queue); + } + return; + } +#endif + if (ngx_queue_empty(&w->watcher_queue)) ngx_queue_insert_tail(&loop->watcher_queue, &w->watcher_queue); diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index fa090709..378903a6 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -84,12 +84,6 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { assert(w->fd >= 0); assert(w->fd < (int) loop->nwatchers); - /* Filter out no-op changes. This is for compatibility with the event ports - * backend, see uv__io_start(). - */ - if (w->events == w->pevents) - continue; - if ((w->events & UV__POLLIN) == 0 && (w->pevents & UV__POLLIN) != 0) { filter = EVFILT_READ; fflags = 0; diff --git a/src/unix/linux-core.c b/src/unix/linux-core.c index 7c01d780..e1a75150 100644 --- a/src/unix/linux-core.c +++ b/src/unix/linux-core.c @@ -140,12 +140,6 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { assert(w->fd >= 0); assert(w->fd < (int) loop->nwatchers); - /* Filter out no-op changes. This is for compatibility with the event ports - * backend, see the comment in uv__io_start(). - */ - if (w->events == w->pevents) - continue; - e.events = w->pevents; e.data = w->fd;