def _handle_events(self, fd, events): while True: try: connection, address = self._socket.accept() # socket 处理 except socket.error, e: if e[0] in (errno.EWOULDBLOCK, errno.EAGAIN): return raise # SSL 处理 if self.ssl_options is not None: assert ssl, "Python 2.6+ and OpenSSL required for SSL" connection = ssl.wrap_socket(connection, server_side=True, **self.ssl_options) try: stream = iostream.IOStream(connection, io_loop=self.io_loop) # 关键调用 # 关键调用: HTTPConnection() 类, 本模块中定义 # # HTTPConnection(stream, address, self.request_callback, self.no_keep_alive, self.xheaders) except: logging.error("Error in connection callback", exc_info=True)
def __init__(self, sock, data_callback, control_callback=None, close_callback=None, io_loop=None, name=None): """Initiate the network channel for socket server to receive/send messages. Args: sock: The socket for receiving / sending messages. data_callback: The handler for data messages. Function fingerprint: callback(buf, offset, num_bytes) control_callback: The handler for control messages. Function fingerprint: callback(buf, offset, num_bytes) close_callback: The callback method triggered when this channel closed. Function fingerprint: callback() io_loop: The IO loop, on which the read/write operations depends; default using global IOLoop instance. name: The name of this object, could be used in debug info output. """ self._stream = iostream.IOStream(sock, io_loop, name) self._stream.set_close_callback(close_callback) self._data_handler = _callback_to_read_handler(self, data_callback) self._control_handler = _callback_to_read_handler( self, control_callback) self._name = name self._header_parser = struct.struct("<i") self._header_buf = bytearray(4)
def __init__(self, sock, data_callback, control_callback=None, close_callback=None, io_loop=None, name=None): self._stream = iostream.IOStream(sock, io_loop, name) self._stream.set_close_callback(close_callback) self._data_handler = _callback_to_read_handler(self, data_callback) self._name = name
def _handle_events(self, fd, events): while True: try: connection, address = self._socket.accept() except socket.error, e: if e[0] in (errno.EWOULDBLOCK, errno.EAGAIN): return raise try: stream = iostream.IOStream(connection, io_loop=self.io_loop) HTTPConnection(stream, address, self.request_callback, self.no_keep_alive, self.xheaders) except: logging.error("Error in connection callback", exc_info=True)
def __init__(self, sock): self.stream = iostream.IOStream(sock) self.resp = bytearray( "HTTP/1.1 200 OK\r\nKeep-Alive: timeout=5, max=100\r\nConnection: Keep-Alive\r\nContent-Length: 121\r\n\r\nHello world!\r\n" ) self.resp_size = len(self.resp)
def __init__(self, sock): self.stream = iostream.IOStream(sock)
def __init__(self, domain, uri): self.domain = domain self.uri = uri s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) self.stream = iostream.IOStream(s)