def _doReadOrWrite(self, selectable, fd, event, POLLIN, POLLOUT, log, faildict={ error.ConnectionDone: failure.Failure(error.ConnectionDone()), error.ConnectionLost: failure.Failure(error.ConnectionLost()) }): why = None inRead = False if event & POLL_DISCONNECTED and not (event & POLLIN): why = main.CONNECTION_LOST else: try: if event & POLLIN: why = selectable.doRead() inRead = True if not why and event & POLLOUT: why = selectable.doWrite() inRead = False if not selectable.fileno() == fd: why = error.ConnectionFdescWentAway('Filedescriptor went away') inRead = False except AttributeError, ae: if "'NoneType' object has no attribute 'writeHeaders'" not in ae.message: log.deferr() why = sys.exc_info()[1] else: why = None except:
def _doReadOrWrite(self, selectable, fd, event): why = None inRead = False if event & POLL_DISCONNECTED and not (event & POLLIN): if fd in self._reads: why = main.CONNECTION_DONE inRead = True else: why = main.CONNECTION_LOST else: try: if event & POLLIN: why = selectable.doRead() inRead = True if not why and event & POLLOUT: why = selectable.doWrite() inRead = False if not selectable.fileno() == fd: why = error.ConnectionFdescWentAway( 'Filedescriptor went away') inRead = False except: log.deferr() why = sys.exc_info()[1] if why: self._disconnectSelectable(selectable, why, inRead)
def _doReadOrWrite(self, selectable, fd, event): """ fd is available for read or write, make the work and raise errors if necessary. """ why = None inRead = False if event & _POLL_DISCONNECTED and not (event & _epoll.IN): why = CONNECTION_LOST else: try: if event & _epoll.IN: why = selectable.doRead() inRead = True if not why and event & _epoll.OUT: why = selectable.doWrite() inRead = False if selectable.fileno() != fd: why = error.ConnectionFdescWentAway( 'Filedescriptor went away') inRead = False except: log.err() why = sys.exc_info()[1] if why: self._disconnectSelectable(selectable, why, inRead)
def _doReadOrWrite( self, selectable, fd, event, POLLIN, POLLOUT, log, faildict={ error.ConnectionDone: failure.Failure(error.ConnectionDone()), error.ConnectionLost: failure.Failure(error.ConnectionLost()) }): why = None inRead = False if event & POLL_DISCONNECTED and not (event & POLLIN): why = main.CONNECTION_LOST else: try: if event & POLLIN: why = selectable.doRead() inRead = True if not why and event & POLLOUT: why = selectable.doWrite() inRead = False if not selectable.fileno() == fd: why = error.ConnectionFdescWentAway( 'Filedescriptor went away') inRead = False except: log.deferr() why = sys.exc_info()[1] if why: self._disconnectSelectable(selectable, why, inRead)
def _doReadOrWrite(self, selectable, fd, event, POLLIN, POLLOUT, log, faildict=None): if not faildict: faildict = { error.ConnectionDone: failure.Failure(error.ConnectionDone()), error.ConnectionLost: failure.Failure(error.ConnectionLost()) } why = None inRead = False if event & POLL_DISCONNECTED and not (event & POLLIN): why = main.CONNECTION_LOST else: try: if event & POLLIN: why = selectable.doRead() inRead = True if not why and event & POLLOUT: why = selectable.doWrite() inRead = False if not selectable.fileno() == fd: why = error.ConnectionFdescWentAway( 'Filedescriptor went away') inRead = False except AttributeError as ae: if "'NoneType' object has no attribute 'writeHeaders'" not in six.text_type( ae): log.deferr() why = sys.exc_info()[1] else: why = None except: log.deferr() why = sys.exc_info()[1] if why: try: self._disconnectSelectable(selectable, why, inRead) except RuntimeError: pass
from twisted.internet.interfaces import (IReactorTCP, IReactorUDP, IReactorSSL, _IReactorArbitrary, IReactorSocket) from twisted.internet.interfaces import IReactorProcess, IReactorMulticast from twisted.internet.interfaces import IHalfCloseableDescriptor from twisted.internet import error from twisted.internet import tcp, udp from twisted.python import log, failure, util from twisted.persisted import styles from twisted.python.runtime import platformType, platform from twisted.internet.base import ReactorBase, _SignalReactorMixin from twisted.internet.main import CONNECTION_DONE, CONNECTION_LOST # Exceptions that doSelect might return frequently _NO_FILENO = error.ConnectionFdescWentAway('Handler has no fileno method') _NO_FILEDESC = error.ConnectionFdescWentAway('File descriptor lost') try: from twisted.protocols import tls except ImportError: tls = None try: from twisted.internet import ssl except ImportError: ssl = None try: from twisted.internet import unix unixEnabled = True except ImportError:
TLSMemoryBIOFactory = None _extraInterfaces = () warnings.warn( "pyOpenSSL 0.10 or newer is required for SSL support in iocpreactor. " "It is missing, so the reactor will not support SSL APIs.") else: _extraInterfaces = (interfaces.IReactorSSL,) MAX_TIMEOUT = 2000 # 2 seconds, see doIteration for explanation EVENTS_PER_LOOP = 1000 # XXX: what's a good value here? # keys to associate with normal and waker events KEY_NORMAL, KEY_WAKEUP = range(2) _NO_GETHANDLE = error.ConnectionFdescWentAway( 'Handler has no getFileHandle method') _NO_FILEDESC = error.ConnectionFdescWentAway('Filedescriptor went away') class IOCPReactor(base._SignalReactorMixin, base.ReactorBase, _ThreadedWin32EventsMixin): implements(interfaces.IReactorTCP, interfaces.IReactorUDP, interfaces.IReactorMulticast, interfaces.IReactorProcess, *_extraInterfaces) port = None def __init__(self): base.ReactorBase.__init__(self) self.port = _iocp.CompletionPort()