electron/shell/common/node_bindings_mac.cc
Charles Kerr 05dfd14913
refactor: add EmitWarning(v8::Isolate*) helper (#43722)
* refactor: add EmitWarning(Isolate*, ...) warning

* chore: remove EmitWarning(node::Environment*, ...)

* chore: add code comments

* fixup! refactor: add EmitWarning(Isolate*, ...) warning

* chore: remove unused node #includes
2024-09-16 15:53:04 -05:00

46 lines
1.1 KiB
C++

// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/common/node_bindings_mac.h"
#include <errno.h>
#include <sys/select.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/types.h>
namespace electron {
NodeBindingsMac::NodeBindingsMac(BrowserEnvironment browser_env)
: NodeBindings(browser_env) {}
void NodeBindingsMac::PollEvents() {
auto* const event_loop = uv_loop();
struct timeval tv;
int timeout = uv_backend_timeout(event_loop);
if (timeout != -1) {
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;
}
fd_set readset;
int fd = uv_backend_fd(event_loop);
FD_ZERO(&readset);
FD_SET(fd, &readset);
// Wait for new libuv events.
int r;
do {
r = select(fd + 1, &readset, nullptr, nullptr,
timeout == -1 ? nullptr : &tv);
} while (r == -1 && errno == EINTR);
}
// static
std::unique_ptr<NodeBindings> NodeBindings::Create(BrowserEnvironment env) {
return std::make_unique<NodeBindingsMac>(env);
}
} // namespace electron