node_bindings_mac.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "shell/common/node_includes.h"
  11. namespace electron {
  12. NodeBindingsMac::NodeBindingsMac(BrowserEnvironment browser_env)
  13. : NodeBindings(browser_env) {}
  14. void NodeBindingsMac::PollEvents() {
  15. auto* const event_loop = uv_loop();
  16. struct timeval tv;
  17. int timeout = uv_backend_timeout(event_loop);
  18. if (timeout != -1) {
  19. tv.tv_sec = timeout / 1000;
  20. tv.tv_usec = (timeout % 1000) * 1000;
  21. }
  22. fd_set readset;
  23. int fd = uv_backend_fd(event_loop);
  24. FD_ZERO(&readset);
  25. FD_SET(fd, &readset);
  26. // Wait for new libuv events.
  27. int r;
  28. do {
  29. r = select(fd + 1, &readset, nullptr, nullptr,
  30. timeout == -1 ? nullptr : &tv);
  31. } while (r == -1 && errno == EINTR);
  32. }
  33. // static
  34. NodeBindings* NodeBindings::Create(BrowserEnvironment browser_env) {
  35. return new NodeBindingsMac(browser_env);
  36. }
  37. } // namespace electron