issue #333: add versioning to EpollPoller too.

issue260
David Wilson 6 years ago
parent 73cda2994f
commit 22b4b186d7

@ -755,14 +755,6 @@ class EpollPoller(mitogen.core.Poller):
def close(self): def close(self):
self._epoll.close() self._epoll.close()
@property
def readers(self):
return list(self._rfds.items())
@property
def writers(self):
return list(self._wfds.items())
def _control(self, fd): def _control(self, fd):
mitogen.core._vv and IOLOG.debug('%r._control(%r)', self, fd) mitogen.core._vv and IOLOG.debug('%r._control(%r)', self, fd)
mask = (((fd in self._rfds) and select.EPOLLIN) | mask = (((fd in self._rfds) and select.EPOLLIN) |
@ -780,7 +772,7 @@ class EpollPoller(mitogen.core.Poller):
def start_receive(self, fd, data=None): def start_receive(self, fd, data=None):
mitogen.core._vv and IOLOG.debug('%r.start_receive(%r, %r)', mitogen.core._vv and IOLOG.debug('%r.start_receive(%r, %r)',
self, fd, data) self, fd, data)
self._rfds[fd] = data or fd self._rfds[fd] = (data or fd, self._generation)
self._control(fd) self._control(fd)
def stop_receive(self, fd): def stop_receive(self, fd):
@ -791,7 +783,7 @@ class EpollPoller(mitogen.core.Poller):
def start_transmit(self, fd, data=None): def start_transmit(self, fd, data=None):
mitogen.core._vv and IOLOG.debug('%r.start_transmit(%r, %r)', mitogen.core._vv and IOLOG.debug('%r.start_transmit(%r, %r)',
self, fd, data) self, fd, data)
self._wfds[fd] = data or fd self._wfds[fd] = (data or fd, self._generation)
self._control(fd) self._control(fd)
def stop_transmit(self, fd): def stop_transmit(self, fd):
@ -802,20 +794,24 @@ class EpollPoller(mitogen.core.Poller):
_inmask = (getattr(select, 'EPOLLIN', 0) | _inmask = (getattr(select, 'EPOLLIN', 0) |
getattr(select, 'EPOLLHUP', 0)) getattr(select, 'EPOLLHUP', 0))
def poll(self, timeout=None): def _poll(self, timeout):
the_timeout = -1 the_timeout = -1
if timeout is not None: if timeout is not None:
the_timeout = timeout the_timeout = timeout
events, _ = mitogen.core.io_op(self._epoll.poll, the_timeout, 32) events, _ = mitogen.core.io_op(self._epoll.poll, the_timeout, 32)
for fd, event in events: for fd, event in events:
if event & self._inmask and fd in self._rfds: if event & self._inmask:
data, gen = self._rfds.get(fd, (None, None))
if gen and gen < self._generation:
# Events can still be read for an already-discarded fd. # Events can still be read for an already-discarded fd.
mitogen.core._vv and IOLOG.debug('%r: POLLIN: %r', self, fd) mitogen.core._vv and IOLOG.debug('%r: POLLIN: %r', self, fd)
yield self._rfds[fd] yield data
if event & select.EPOLLOUT and fd in self._wfds: if event & select.EPOLLOUT:
data, gen = self._wfds.get(fd, (None, None))
if gen and gen < self._generation:
mitogen.core._vv and IOLOG.debug('%r: POLLOUT: %r', self, fd) mitogen.core._vv and IOLOG.debug('%r: POLLOUT: %r', self, fd)
yield self._wfds[fd] yield data
POLLER_BY_SYSNAME = { POLLER_BY_SYSNAME = {

Loading…
Cancel
Save