def __init__(self, concurrency=INFINITE): """An event loop that runs using Windows IOCP instead of the default Selector""" super().__init__() self._port = _overlapped.CreateIoCompletionPort( _overlapped.INVALID_HANDLE_VALUE, NULL, 0, concurrency) self._current_iocp = dict() # Registered IOCPs self._open_ports = list()
def __init__(self, concurrency=0xffffffff): self._loop = None self._results = [] self._iocp = _overlapped.CreateIoCompletionPort( _overlapped.INVALID_HANDLE_VALUE, NULL, 0, concurrency) self._cache = {} self._registered = weakref.WeakSet() self._unregistered = [] self._stopped_serving = weakref.WeakSet()
async def connect(protocol_factory: Callable[..., ConnectionBase], address: str = None, port: int = None, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None, bufsize: int = 1024, sock: socket = None): if sock is not None: if fileno is not None: raise ValueError("You cannot specify a fileno AND a socket!") try: sock.getpeername() connected = False # We want to check if the sock is connected already except OSError: # It'll raise an OSError if we try to getpeername of an unconnected sock if address is not None or port is not None: raise ValueError( "You cannot specify both an address/port AND a connected socket!" ) from None connected = True else: sock = socket(family=family, type=type, proto=proto, fileno=fileno) connected = False connection = protocol_factory( socket=sock, host=(address, port), bufsize=bufsize) # All protos need these args if not connected: await connection._connect( ) # If the sock isn't connected, connect "asynchronously" loop = await get_loop() if not isinstance(loop, IOCPLoop): await create_writer(sock, connection._writer_callback ) # Create our reader and writer else: if sock.fileno() not in loop._open_ports: _overlapped.CreateIoCompletionPort(sock.fileno(), loop._port, 0, 0) loop._open_ports.append(sock.fileno()) await create_reader(sock, connection._reader_callback) return connection
def _register_with_iocp(self, obj): # To get notifications of finished ops on this objects sent to the # completion port, were must register the handle. if obj not in self._registered: self._registered.add(obj) _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
def wrap_socket(self, file): wrapped = IOCPFile(file) self._open_ports.append(file.fileno()) _overlapped.CreateIoCompletionPort(file.fileno(), self._port, 0, 0) return wrapped
def __init__(self, concurrency=INFINITE): super().__init__() self._port = _overlapped.CreateIoCompletionPort( _overlapped.INVALID_HANDLE_VALUE, NULL, 0, concurrency) self._current_iocp = dict() # Registered IOCPs self._open_ports = list()