2014-10-31 21:17:05 +03:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-04-25 13:49:37 +04:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-02-14 18:39:57 +04:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 04:30:26 +04:00
|
|
|
#include "atom/common/node_bindings_linux.h"
|
2014-02-14 18:39:57 +04:00
|
|
|
|
2014-02-21 09:21:02 +04:00
|
|
|
#include <sys/epoll.h>
|
|
|
|
|
2014-02-14 18:39:57 +04:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
NodeBindingsLinux::NodeBindingsLinux(bool is_browser)
|
2014-02-21 09:21:02 +04:00
|
|
|
: NodeBindings(is_browser),
|
|
|
|
epoll_(epoll_create(1)) {
|
|
|
|
int backend_fd = uv_backend_fd(uv_loop_);
|
|
|
|
struct epoll_event ev = { 0 };
|
|
|
|
ev.events = EPOLLIN;
|
|
|
|
ev.data.fd = backend_fd;
|
|
|
|
epoll_ctl(epoll_, EPOLL_CTL_ADD, backend_fd, &ev);
|
2014-02-14 18:39:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NodeBindingsLinux::~NodeBindingsLinux() {
|
|
|
|
}
|
|
|
|
|
2014-02-21 09:21:02 +04:00
|
|
|
void NodeBindingsLinux::RunMessageLoop() {
|
|
|
|
// Get notified when libuv's watcher queue changes.
|
|
|
|
uv_loop_->data = this;
|
|
|
|
uv_loop_->on_watcher_queue_updated = OnWatcherQueueChanged;
|
|
|
|
|
|
|
|
NodeBindings::RunMessageLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void NodeBindingsLinux::OnWatcherQueueChanged(uv_loop_t* loop) {
|
|
|
|
NodeBindingsLinux* self = static_cast<NodeBindingsLinux*>(loop->data);
|
|
|
|
|
|
|
|
// We need to break the io polling in the epoll thread when loop's watcher
|
|
|
|
// queue changes, otherwise new events cannot be notified.
|
|
|
|
self->WakeupEmbedThread();
|
|
|
|
}
|
|
|
|
|
2014-02-14 18:39:57 +04:00
|
|
|
void NodeBindingsLinux::PollEvents() {
|
2014-02-21 09:21:02 +04:00
|
|
|
int timeout = uv_backend_timeout(uv_loop_);
|
|
|
|
|
|
|
|
// Wait for new libuv events.
|
|
|
|
int r;
|
|
|
|
do {
|
|
|
|
struct epoll_event ev;
|
|
|
|
r = epoll_wait(epoll_, &ev, 1, timeout);
|
|
|
|
} while (r == -1 && errno == EINTR);
|
2014-02-14 18:39:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
NodeBindings* NodeBindings::Create(bool is_browser) {
|
|
|
|
return new NodeBindingsLinux(is_browser);
|
|
|
|
}
|
|
|
|
|
2014-02-20 21:07:47 +04:00
|
|
|
} // namespace atom
|