def _handle_connect(self, tcp_conn: TcpConnection) -> None: "The connection has succeeded." self.tcp_conn = tcp_conn self._set_read_timeout('connect') tcp_conn.on('data', self.handle_input) tcp_conn.on('close', self._conn_closed) tcp_conn.on('pause', self._req_body_pause) # FIXME: should this be done AFTER _req_start? self.output(b"") # kick the output buffer self.tcp_conn.pause(False)
def release_conn(self, tcp_conn: TcpConnection, scheme: bytes) -> None: "Add an idle connection back to the pool." tcp_conn.removeListeners('close') origin = (scheme, tcp_conn.host, tcp_conn.port) if tcp_conn.tcp_connected: def idle_close(): "Remove the connection from the pool when it closes." if hasattr(tcp_conn, "_idler"): tcp_conn._idler.delete() self._dead_conn(origin) try: self._idle_conns[origin].remove(tcp_conn) except (KeyError, ValueError): pass tcp_conn.on('close', idle_close) if self.idle_timeout > 0: tcp_conn._idler = self.loop.schedule(self.idle_timeout, # type: ignore tcp_conn.close) else: tcp_conn.close() self._dead_conn(origin) self._idle_conns[origin].append(tcp_conn) else: self._dead_conn(origin)
def go(conn: TcpConnection) -> None: conn.on('data', out) conn.write(b"GET / HTTP/1.1\r\nHost: %s\r\n\r\n" % test_host) conn.pause(False)
def handle_conn(self, tcp_conn: TcpConnection) -> None: http_conn = HttpServerConnection(tcp_conn, self) tcp_conn.on('data', http_conn.handle_input) tcp_conn.on('close', http_conn.conn_closed) tcp_conn.on('pause', http_conn.res_body_pause) tcp_conn.pause(False)