def socket_patch(protocol, sock_type): if sock_type == socket.SOCK_STREAM: return ServerMockSocket( protocol, sock_type, set_true_listen_socket=mux_select.set_true_listen_socket) else: return socket._old_socket(protocol, sock_type)
def create_true_listen_socket(server_info, protocol, sock_type, blocking=0): ''' Return a socket bound to server_info and set to listen ''' if hasattr(socket, "_old_socket"): true_socket = socket._old_socket(protocol, sock_type) else: true_socket = socket.socket(protocol, sock_type) true_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) true_socket.bind(server_info) true_socket.setblocking(blocking) true_socket.listen(1) return true_socket
def listen(self, _): self.listener = True # Here, we create a *real* socket. # bind it to server_info, and wait for the client SocketDemultiplexer to # connect. After this is done, we can instantiate our own # SocketDemultiplexer. # Assumes that all invocations of bind() are intended for connection to # STS. TODO(cs): STS should tell pox_monkeypatcher exactly what ports it # intends to connect to. If bind() is called for some other port, delegate to # a real socket. if hasattr(socket, "_old_socket"): true_socket = socket._old_socket(self.protocol, self.sock_type) else: true_socket = socket.socket(self.protocol, self.sock_type) true_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) true_socket.bind(self.server_info) true_socket.setblocking(0) true_socket.listen(1) # We give this true socket to select.select and # wait for the client SocketDemultiplexer connection self.set_true_listen_socket(true_socket, self, accept_callback=self._accept_callback)
def socket_patch(protocol, sock_type): if sock_type == socket.SOCK_STREAM: return ServerMockSocket(protocol, sock_type, set_true_listen_socket=mux_select.set_true_listen_socket) else: return socket._old_socket(protocol, sock_type)
def socket_patch(protocol, sock_type): if sock_type == socket.SOCK_STREAM: return STSMockSocket(protocol, sock_type) else: socket._old_socket(protocol, sock_type)