我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用select.KQ_EV_EOF。
def poll(self, timeout): kevents = self._kqueue.control(None, 1000, timeout) events = {} for kevent in kevents: fd = kevent.ident if kevent.filter == select.KQ_FILTER_READ: events[fd] = events.get(fd, 0) | IOLoop.READ if kevent.filter == select.KQ_FILTER_WRITE: if kevent.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] = IOLoop.ERROR else: events[fd] = events.get(fd, 0) | IOLoop.WRITE if kevent.flags & select.KQ_EV_ERROR: events[fd] = events.get(fd, 0) | IOLoop.ERROR return events.items()
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()
def poll(self, timeout): kevents = self.poller.control(None, 500, timeout) events = [(kevent.ident, _AsyncPoller._Read if kevent.filter == select.KQ_FILTER_READ else _AsyncPoller._Write if kevent.filter == select.KQ_FILTER_WRITE else _AsyncPoller._Hangup if kevent.flags == select.KQ_EV_EOF else _AsyncPoller._Error if kevent.flags == select.KQ_EV_ERROR else 0) for kevent in kevents] return events
def _doWriteOrRead(self, selectable, fd, event): """ Private method called when a FD is ready for reading, writing or was lost. Do the work and raise errors where necessary. """ why = None inRead = False (filter, flags, data, fflags) = ( event.filter, event.flags, event.data, event.fflags) if flags & KQ_EV_EOF and data and fflags: why = main.CONNECTION_LOST else: try: if selectable.fileno() == -1: inRead = False why = posixbase._NO_FILEDESC else: if filter == KQ_FILTER_READ: inRead = True why = selectable.doRead() if filter == KQ_FILTER_WRITE: inRead = False why = selectable.doWrite() except: # Any exception from application code gets logged and will # cause us to disconnect the selectable. why = failure.Failure() log.err(why, "An exception was raised from application code" \ " while processing a reactor selectable") if why: self._disconnectSelectable(selectable, why, inRead)
def poll(self, timeout, _len=len, _READ=select.KQ_FILTER_READ, _WRITE=select.KQ_FILTER_WRITE, _EOF=select.KQ_EV_EOF, _ERROR=select.KQ_EV_ERROR): try: kevents = self._kqueue.control(None, _len(self.socket_map), timeout) except OSError as err: if err.errno == errno.EINTR: return raise for kevent in kevents: inst = self.socket_map.get(kevent.ident) if inst is None: continue if kevent.filter == _READ: if inst.readable(): _read(inst) if kevent.filter == _WRITE: if kevent.flags & _EOF: # If an asynchronous connection is refused, # kqueue returns a write event with the EOF # flag set. # 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. inst.handle_close() else: if inst.writable(): _write(inst) if kevent.flags & _ERROR: inst.handle_close() # =================================================================== # --- choose the better poller for this platform # ===================================================================