2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-13 15:05:13 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/common/node_bindings_mac.h"
|
2013-04-13 15:05:13 +00:00
|
|
|
|
2013-07-22 06:58:25 +00:00
|
|
|
#include <errno.h>
|
2016-05-03 06:54:21 +00:00
|
|
|
#include <sys/select.h>
|
2013-04-19 13:21:04 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
2013-04-13 15:05:13 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2017-03-08 08:33:44 +00:00
|
|
|
NodeBindingsMac::NodeBindingsMac(BrowserEnvironment browser_env)
|
2018-04-18 01:55:30 +00:00
|
|
|
: NodeBindings(browser_env) {}
|
2013-04-13 15:05:13 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
NodeBindingsMac::~NodeBindingsMac() {}
|
2013-04-13 15:05:13 +00:00
|
|
|
|
2014-01-18 08:56:46 +00:00
|
|
|
void NodeBindingsMac::RunMessageLoop() {
|
|
|
|
// Get notified when libuv's watcher queue changes.
|
|
|
|
uv_loop_->data = this;
|
|
|
|
uv_loop_->on_watcher_queue_updated = OnWatcherQueueChanged;
|
|
|
|
|
|
|
|
NodeBindings::RunMessageLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void NodeBindingsMac::OnWatcherQueueChanged(uv_loop_t* loop) {
|
|
|
|
NodeBindingsMac* self = static_cast<NodeBindingsMac*>(loop->data);
|
|
|
|
|
|
|
|
// We need to break the io polling in the kqueue thread when loop's watcher
|
|
|
|
// queue changes, otherwise new events cannot be notified.
|
|
|
|
self->WakeupEmbedThread();
|
|
|
|
}
|
|
|
|
|
2013-07-22 06:58:25 +00:00
|
|
|
void NodeBindingsMac::PollEvents() {
|
2016-05-03 06:54:21 +00:00
|
|
|
struct timeval tv;
|
2013-07-22 06:58:25 +00:00
|
|
|
int timeout = uv_backend_timeout(uv_loop_);
|
|
|
|
if (timeout != -1) {
|
2016-05-03 06:54:21 +00:00
|
|
|
tv.tv_sec = timeout / 1000;
|
|
|
|
tv.tv_usec = (timeout % 1000) * 1000;
|
2013-04-13 15:05:13 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 06:54:21 +00:00
|
|
|
fd_set readset;
|
|
|
|
int fd = uv_backend_fd(uv_loop_);
|
|
|
|
FD_ZERO(&readset);
|
|
|
|
FD_SET(fd, &readset);
|
|
|
|
|
2013-07-22 06:58:25 +00:00
|
|
|
// Wait for new libuv events.
|
|
|
|
int r;
|
|
|
|
do {
|
2016-07-10 13:56:42 +00:00
|
|
|
r = select(fd + 1, &readset, nullptr, nullptr,
|
|
|
|
timeout == -1 ? nullptr : &tv);
|
2013-07-22 06:58:25 +00:00
|
|
|
} while (r == -1 && errno == EINTR);
|
2013-04-13 15:05:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2017-03-08 08:33:44 +00:00
|
|
|
NodeBindings* NodeBindings::Create(BrowserEnvironment browser_env) {
|
|
|
|
return new NodeBindingsMac(browser_env);
|
2013-04-13 15:05:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|