node_bindings_mac.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/common/node_bindings_mac.h"
  5. #include <errno.h>
  6. #include <sys/select.h>
  7. #include <sys/sysctl.h>
  8. #include <sys/time.h>
  9. #include <sys/types.h>
  10. namespace electron {
  11. NodeBindingsMac::NodeBindingsMac(BrowserEnvironment browser_env)
  12. : NodeBindings(browser_env) {}
  13. void NodeBindingsMac::PollEvents() {
  14. auto* const event_loop = uv_loop();
  15. struct timeval tv;
  16. int timeout = uv_backend_timeout(event_loop);
  17. if (timeout != -1) {
  18. tv.tv_sec = timeout / 1000;
  19. tv.tv_usec = (timeout % 1000) * 1000;
  20. }
  21. fd_set readset;
  22. int fd = uv_backend_fd(event_loop);
  23. FD_ZERO(&readset);
  24. FD_SET(fd, &readset);
  25. // Wait for new libuv events.
  26. int r;
  27. do {
  28. r = select(fd + 1, &readset, nullptr, nullptr,
  29. timeout == -1 ? nullptr : &tv);
  30. } while (r == -1 && errno == EINTR);
  31. }
  32. // static
  33. std::unique_ptr<NodeBindings> NodeBindings::Create(BrowserEnvironment env) {
  34. return std::make_unique<NodeBindingsMac>(env);
  35. }
  36. } // namespace electron