node_bindings_linux.cc 938 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2014 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_linux.h"
  5. #include <sys/epoll.h>
  6. namespace electron {
  7. NodeBindingsLinux::NodeBindingsLinux(BrowserEnvironment browser_env)
  8. : NodeBindings(browser_env), epoll_(epoll_create(1)) {
  9. int backend_fd = uv_backend_fd(uv_loop_);
  10. struct epoll_event ev = {0};
  11. ev.events = EPOLLIN;
  12. ev.data.fd = backend_fd;
  13. epoll_ctl(epoll_, EPOLL_CTL_ADD, backend_fd, &ev);
  14. }
  15. void NodeBindingsLinux::PollEvents() {
  16. int timeout = uv_backend_timeout(uv_loop_);
  17. // Wait for new libuv events.
  18. int r;
  19. do {
  20. struct epoll_event ev;
  21. r = epoll_wait(epoll_, &ev, 1, timeout);
  22. } while (r == -1 && errno == EINTR);
  23. }
  24. // static
  25. NodeBindings* NodeBindings::Create(BrowserEnvironment browser_env) {
  26. return new NodeBindingsLinux(browser_env);
  27. }
  28. } // namespace electron