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. #include "shell/common/node_includes.h"
  11. namespace electron {
  12. NodeBindingsMac::NodeBindingsMac(BrowserEnvironment browser_env)
  13. : NodeBindings(browser_env) {}
  14. void NodeBindingsMac::PollEvents() {
  15. struct timeval tv;
  16. int timeout = uv_backend_timeout(uv_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(uv_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. NodeBindings* NodeBindings::Create(BrowserEnvironment browser_env) {
  34. return new NodeBindingsMac(browser_env);
  35. }
  36. } // namespace electron