From b15c07e1a837b6d40c117dacb42d838aeaa8a85c Mon Sep 17 00:00:00 2001 From: Ryan Patterson Date: Mon, 2 May 2016 23:54:21 -0700 Subject: [PATCH] Use select to query the uv kqueue This resolves #38. I've verified that events still get processed like they should on El Capitan 10.11.3 (15D21). --- atom/common/node_bindings_mac.cc | 24 +++++++++++------------- atom/common/node_bindings_mac.h | 3 --- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/atom/common/node_bindings_mac.cc b/atom/common/node_bindings_mac.cc index 877497d5a..9e61d27f4 100644 --- a/atom/common/node_bindings_mac.cc +++ b/atom/common/node_bindings_mac.cc @@ -5,6 +5,7 @@ #include "atom/common/node_bindings_mac.h" #include +#include #include #include #include @@ -14,13 +15,7 @@ namespace atom { NodeBindingsMac::NodeBindingsMac(bool is_browser) - : NodeBindings(is_browser), - kqueue_(kqueue()) { - // Add uv's backend fd to kqueue. - struct kevent ev; - EV_SET(&ev, uv_backend_fd(uv_loop_), EVFILT_READ, EV_ADD | EV_ENABLE, - 0, 0, 0); - kevent(kqueue_, &ev, 1, NULL, 0, NULL); + : NodeBindings(is_browser) { } NodeBindingsMac::~NodeBindingsMac() { @@ -44,19 +39,22 @@ void NodeBindingsMac::OnWatcherQueueChanged(uv_loop_t* loop) { } void NodeBindingsMac::PollEvents() { - struct timespec spec; + struct timeval tv; int timeout = uv_backend_timeout(uv_loop_); if (timeout != -1) { - spec.tv_sec = timeout / 1000; - spec.tv_nsec = (timeout % 1000) * 1000000; + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; } + fd_set readset; + int fd = uv_backend_fd(uv_loop_); + FD_ZERO(&readset); + FD_SET(fd, &readset); + // Wait for new libuv events. int r; do { - struct kevent ev; - r = ::kevent(kqueue_, NULL, 0, &ev, 1, - timeout == -1 ? NULL : &spec); + r = select(fd + 1, &readset, NULL, NULL, timeout == -1 ? NULL : &tv); } while (r == -1 && errno == EINTR); } diff --git a/atom/common/node_bindings_mac.h b/atom/common/node_bindings_mac.h index 03152ada3..96c79ec6f 100644 --- a/atom/common/node_bindings_mac.h +++ b/atom/common/node_bindings_mac.h @@ -23,9 +23,6 @@ class NodeBindingsMac : public NodeBindings { void PollEvents() override; - // Kqueue to poll for uv's backend fd. - int kqueue_; - DISALLOW_COPY_AND_ASSIGN(NodeBindingsMac); }; -- 2.34.1