2014-10-31 12:17:05 -06:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 03:49:37 -06:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-13 09:05:13 -06:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 14:46:59 -06:00
|
|
|
#include "shell/common/node_bindings_mac.h"
|
2013-04-13 09:05:13 -06:00
|
|
|
|
2013-07-22 00:58:25 -06:00
|
|
|
#include <errno.h>
|
2016-05-03 00:54:21 -06:00
|
|
|
#include <sys/select.h>
|
2013-04-19 07:21:04 -06:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2019-06-19 14:46:59 -06:00
|
|
|
#include "shell/common/node_includes.h"
|
2013-04-13 09:05:13 -06:00
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
namespace electron {
|
2013-04-13 09:05:13 -06:00
|
|
|
|
2017-03-08 01:33:44 -07:00
|
|
|
NodeBindingsMac::NodeBindingsMac(BrowserEnvironment browser_env)
|
2018-04-17 19:55:30 -06:00
|
|
|
: NodeBindings(browser_env) {}
|
2013-04-13 09:05:13 -06:00
|
|
|
|
2013-07-22 00:58:25 -06:00
|
|
|
void NodeBindingsMac::PollEvents() {
|
2023-09-07 17:25:17 -06:00
|
|
|
auto* const event_loop = uv_loop();
|
|
|
|
|
2016-05-03 00:54:21 -06:00
|
|
|
struct timeval tv;
|
2023-09-07 17:25:17 -06:00
|
|
|
int timeout = uv_backend_timeout(event_loop);
|
2013-07-22 00:58:25 -06:00
|
|
|
if (timeout != -1) {
|
2016-05-03 00:54:21 -06:00
|
|
|
tv.tv_sec = timeout / 1000;
|
|
|
|
tv.tv_usec = (timeout % 1000) * 1000;
|
2013-04-13 09:05:13 -06:00
|
|
|
}
|
|
|
|
|
2016-05-03 00:54:21 -06:00
|
|
|
fd_set readset;
|
2023-09-07 17:25:17 -06:00
|
|
|
int fd = uv_backend_fd(event_loop);
|
2016-05-03 00:54:21 -06:00
|
|
|
FD_ZERO(&readset);
|
|
|
|
FD_SET(fd, &readset);
|
|
|
|
|
2013-07-22 00:58:25 -06:00
|
|
|
// Wait for new libuv events.
|
|
|
|
int r;
|
|
|
|
do {
|
2016-07-10 07:56:42 -06:00
|
|
|
r = select(fd + 1, &readset, nullptr, nullptr,
|
|
|
|
timeout == -1 ? nullptr : &tv);
|
2013-07-22 00:58:25 -06:00
|
|
|
} while (r == -1 && errno == EINTR);
|
2013-04-13 09:05:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2017-03-08 01:33:44 -07:00
|
|
|
NodeBindings* NodeBindings::Create(BrowserEnvironment browser_env) {
|
|
|
|
return new NodeBindingsMac(browser_env);
|
2013-04-13 09:05:13 -06:00
|
|
|
}
|
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
} // namespace electron
|