You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 line
1.0KB

  1. import errno
  2. from eventlet import patcher, support
  3. from eventlet.hubs import hub, poll
  4. select = patcher.original('select')
  5. def is_available():
  6. return hasattr(select, 'epoll')
  7. # NOTE: we rely on the fact that the epoll flag constants
  8. # are identical in value to the poll constants
  9. class Hub(poll.Hub):
  10. def __init__(self, clock=None):
  11. super(Hub, self).__init__(clock=clock)
  12. self.poll = select.epoll()
  13. def add(self, evtype, fileno, cb, tb, mac):
  14. oldlisteners = bool(self.listeners[self.READ].get(fileno) or
  15. self.listeners[self.WRITE].get(fileno))
  16. # not super() to avoid double register()
  17. listener = hub.BaseHub.add(self, evtype, fileno, cb, tb, mac)
  18. try:
  19. self.register(fileno, new=not oldlisteners)
  20. except IOError as ex: # ignore EEXIST, #80
  21. if support.get_errno(ex) != errno.EEXIST:
  22. raise
  23. return listener
  24. def do_poll(self, seconds):
  25. return self.poll.poll(seconds)