reactor: Be explicit on which handlers are timer_handler vs file_handler
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
0546c18d27
commit
afc10400e3
|
@ -82,23 +82,23 @@ class SelectReactor:
|
||||||
self._g_dispatch = None
|
self._g_dispatch = None
|
||||||
self._greenlets = []
|
self._greenlets = []
|
||||||
# Timers
|
# Timers
|
||||||
def _note_time(self, t):
|
def _note_time(self, timer_handler):
|
||||||
nexttime = t.waketime
|
nexttime = timer_handler.waketime
|
||||||
if nexttime < self._next_timer:
|
if nexttime < self._next_timer:
|
||||||
self._next_timer = nexttime
|
self._next_timer = nexttime
|
||||||
def update_timer(self, t, nexttime):
|
def update_timer(self, timer_handler, nexttime):
|
||||||
t.waketime = nexttime
|
timer_handler.waketime = nexttime
|
||||||
self._note_time(t)
|
self._note_time(timer_handler)
|
||||||
def register_timer(self, callback, waketime = NEVER):
|
def register_timer(self, callback, waketime = NEVER):
|
||||||
handler = ReactorTimer(callback, waketime)
|
timer_handler = ReactorTimer(callback, waketime)
|
||||||
timers = list(self._timers)
|
timers = list(self._timers)
|
||||||
timers.append(handler)
|
timers.append(timer_handler)
|
||||||
self._timers = timers
|
self._timers = timers
|
||||||
self._note_time(handler)
|
self._note_time(timer_handler)
|
||||||
return handler
|
return timer_handler
|
||||||
def unregister_timer(self, handler):
|
def unregister_timer(self, timer_handler):
|
||||||
timers = list(self._timers)
|
timers = list(self._timers)
|
||||||
timers.pop(timers.index(handler))
|
timers.pop(timers.index(timer_handler))
|
||||||
self._timers = timers
|
self._timers = timers
|
||||||
def _check_timers(self, eventtime):
|
def _check_timers(self, eventtime):
|
||||||
if eventtime < self._next_timer:
|
if eventtime < self._next_timer:
|
||||||
|
@ -180,11 +180,11 @@ class SelectReactor:
|
||||||
return ReactorMutex(self, is_locked)
|
return ReactorMutex(self, is_locked)
|
||||||
# File descriptors
|
# File descriptors
|
||||||
def register_fd(self, fd, callback):
|
def register_fd(self, fd, callback):
|
||||||
handler = ReactorFileHandler(fd, callback)
|
file_handler = ReactorFileHandler(fd, callback)
|
||||||
self._fds.append(handler)
|
self._fds.append(file_handler)
|
||||||
return handler
|
return file_handler
|
||||||
def unregister_fd(self, handler):
|
def unregister_fd(self, file_handler):
|
||||||
self._fds.pop(self._fds.index(handler))
|
self._fds.pop(self._fds.index(file_handler))
|
||||||
# Main loop
|
# Main loop
|
||||||
def _dispatch_loop(self):
|
def _dispatch_loop(self):
|
||||||
self._g_dispatch = g_dispatch = greenlet.getcurrent()
|
self._g_dispatch = g_dispatch = greenlet.getcurrent()
|
||||||
|
@ -216,16 +216,16 @@ class PollReactor(SelectReactor):
|
||||||
self._fds = {}
|
self._fds = {}
|
||||||
# File descriptors
|
# File descriptors
|
||||||
def register_fd(self, fd, callback):
|
def register_fd(self, fd, callback):
|
||||||
handler = ReactorFileHandler(fd, callback)
|
file_handler = ReactorFileHandler(fd, callback)
|
||||||
fds = self._fds.copy()
|
fds = self._fds.copy()
|
||||||
fds[fd] = callback
|
fds[fd] = callback
|
||||||
self._fds = fds
|
self._fds = fds
|
||||||
self._poll.register(handler, select.POLLIN | select.POLLHUP)
|
self._poll.register(file_handler, select.POLLIN | select.POLLHUP)
|
||||||
return handler
|
return file_handler
|
||||||
def unregister_fd(self, handler):
|
def unregister_fd(self, file_handler):
|
||||||
self._poll.unregister(handler)
|
self._poll.unregister(file_handler)
|
||||||
fds = self._fds.copy()
|
fds = self._fds.copy()
|
||||||
del fds[handler.fd]
|
del fds[file_handler.fd]
|
||||||
self._fds = fds
|
self._fds = fds
|
||||||
# Main loop
|
# Main loop
|
||||||
def _dispatch_loop(self):
|
def _dispatch_loop(self):
|
||||||
|
@ -250,16 +250,16 @@ class EPollReactor(SelectReactor):
|
||||||
self._fds = {}
|
self._fds = {}
|
||||||
# File descriptors
|
# File descriptors
|
||||||
def register_fd(self, fd, callback):
|
def register_fd(self, fd, callback):
|
||||||
handler = ReactorFileHandler(fd, callback)
|
file_handler = ReactorFileHandler(fd, callback)
|
||||||
fds = self._fds.copy()
|
fds = self._fds.copy()
|
||||||
fds[fd] = callback
|
fds[fd] = callback
|
||||||
self._fds = fds
|
self._fds = fds
|
||||||
self._epoll.register(fd, select.EPOLLIN | select.EPOLLHUP)
|
self._epoll.register(fd, select.EPOLLIN | select.EPOLLHUP)
|
||||||
return handler
|
return file_handler
|
||||||
def unregister_fd(self, handler):
|
def unregister_fd(self, file_handler):
|
||||||
self._epoll.unregister(handler.fd)
|
self._epoll.unregister(file_handler.fd)
|
||||||
fds = self._fds.copy()
|
fds = self._fds.copy()
|
||||||
del fds[handler.fd]
|
del fds[file_handler.fd]
|
||||||
self._fds = fds
|
self._fds = fds
|
||||||
# Main loop
|
# Main loop
|
||||||
def _dispatch_loop(self):
|
def _dispatch_loop(self):
|
||||||
|
|
Loading…
Reference in New Issue