|
|
|
@ -890,10 +890,58 @@ class CallSpec(object):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PollPoller(mitogen.core.Poller):
|
|
|
|
|
"""
|
|
|
|
|
Poller based on the POSIX poll(2) interface. Not available on some versions
|
|
|
|
|
of OS X, otherwise it is the preferred poller for small FD counts.
|
|
|
|
|
"""
|
|
|
|
|
SUPPORTED = hasattr(select, 'poll')
|
|
|
|
|
_repr = 'PollPoller()'
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(PollPoller, self).__init__()
|
|
|
|
|
self._pollobj = select.poll()
|
|
|
|
|
|
|
|
|
|
# TODO: no proof we dont need writemask too
|
|
|
|
|
_readmask = (
|
|
|
|
|
getattr(select, 'POLLIN', 0) |
|
|
|
|
|
getattr(select, 'POLLHUP', 0)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def _update(self, fd):
|
|
|
|
|
mask = (((fd in self._rfds) and self._readmask) |
|
|
|
|
|
((fd in self._wfds) and select.POLLOUT))
|
|
|
|
|
if mask:
|
|
|
|
|
self._pollobj.register(fd, mask)
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
self._pollobj.unregister(fd)
|
|
|
|
|
except KeyError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def _poll(self, timeout):
|
|
|
|
|
if timeout:
|
|
|
|
|
timeout *= 1000
|
|
|
|
|
|
|
|
|
|
events, _ = mitogen.core.io_op(self._pollobj.poll, timeout)
|
|
|
|
|
for fd, event in events:
|
|
|
|
|
if event & self._readmask:
|
|
|
|
|
IOLOG.debug('%r: POLLIN|POLLHUP for %r', self, fd)
|
|
|
|
|
data, gen = self._rfds.get(fd, (None, None))
|
|
|
|
|
if gen and gen < self._generation:
|
|
|
|
|
yield data
|
|
|
|
|
if event & select.POLLOUT:
|
|
|
|
|
IOLOG.debug('%r: POLLOUT for %r', self, fd)
|
|
|
|
|
data, gen = self._wfds.get(fd, (None, None))
|
|
|
|
|
if gen and gen < self._generation:
|
|
|
|
|
yield data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KqueuePoller(mitogen.core.Poller):
|
|
|
|
|
"""
|
|
|
|
|
Poller based on the FreeBSD/Darwin kqueue(2) interface.
|
|
|
|
|
"""
|
|
|
|
|
SUPPORTED = hasattr(select, 'kqueue')
|
|
|
|
|
_repr = 'KqueuePoller()'
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
@ -971,6 +1019,7 @@ class EpollPoller(mitogen.core.Poller):
|
|
|
|
|
"""
|
|
|
|
|
Poller based on the Linux epoll(2) interface.
|
|
|
|
|
"""
|
|
|
|
|
SUPPORTED = hasattr(select, 'epoll')
|
|
|
|
|
_repr = 'EpollPoller()'
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
@ -1041,20 +1090,18 @@ class EpollPoller(mitogen.core.Poller):
|
|
|
|
|
yield data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if sys.version_info < (2, 6):
|
|
|
|
|
# 2.4 and 2.5 only had select.select() and select.poll().
|
|
|
|
|
POLLER_BY_SYSNAME = {}
|
|
|
|
|
else:
|
|
|
|
|
POLLER_BY_SYSNAME = {
|
|
|
|
|
'Darwin': KqueuePoller,
|
|
|
|
|
'FreeBSD': KqueuePoller,
|
|
|
|
|
'Linux': EpollPoller,
|
|
|
|
|
}
|
|
|
|
|
# 2.4 and 2.5 only had select.select() and select.poll().
|
|
|
|
|
for _klass in mitogen.core.Poller, PollPoller, KqueuePoller, EpollPoller:
|
|
|
|
|
if _klass.SUPPORTED:
|
|
|
|
|
PREFERRED_POLLER = _klass
|
|
|
|
|
|
|
|
|
|
PREFERRED_POLLER = POLLER_BY_SYSNAME.get(
|
|
|
|
|
os.uname()[0],
|
|
|
|
|
mitogen.core.Poller,
|
|
|
|
|
)
|
|
|
|
|
# For apps that start threads dynamically, it's possible Latch will also get
|
|
|
|
|
# very high-numbered wait fds when there are many connections, and so select()
|
|
|
|
|
# becomes useless there too. So swap in our favourite poller.
|
|
|
|
|
if PollPoller.SUPPORTED:
|
|
|
|
|
mitogen.core.Latch.poller_class = PollPoller
|
|
|
|
|
else:
|
|
|
|
|
mitogen.core.Latch.poller_class = PREFERRED_POLLER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DiagLogStream(mitogen.core.BasicStream):
|
|
|
|
|