def poll(self, timeout):
if timeout < 0:
timeout = None
kevents = self._kqueue.control(None, KQueueLoop.MAX_EVENTS, timeout)
events = {}
for ke in kevents:
fd = ke.ident
if ke.filter == select.KQ_FILTER_READ:
events[fd] = events.get(fd, 0) | EVENT_READ
if ke.filter == select.KQ_FILTER_WRITE:
if ke.flags & select.KQ_EV_EOF:
# If an asynchronous connection is refused, kqueue
# returns a write event with the EOF flag set.
# Turn this into an error for consistency with the
# other IOLoop implementations.
# Note that for read events, EOF may be returned before
# all data has been consumed from the socket buffer,
# so we only check for EOF on write events.
events[fd] = EVENT_ERROR
else:
events[fd] = events.get(fd, 0) | EVENT_WRITE
if ke.flags & select.KQ_EV_ERROR:
events[fd] = events.get(fd, 0) | EVENT_ERROR
return events.iteritems()
评论列表
文章目录