def connect_callback(): if cancel_timer is not None: cancel_timer.cancel() self.hub.unregister(sock) try: sock.getpeername() except socket.error: self.hub.schedule( lambda: self.wake( ClientConnectionError("Could not connect to remote host (%s:%s)" % (host, port)) )) return def finish(e=None): if e: assert isinstance(e, Exception) self.hub.schedule( lambda: self.wake(e) ) else: client.conn = Connection(fsock, ip) client.connected = True self.hub.schedule( lambda: self.wake() ) if client.ssl_ctx: fsock = SSL.Connection(client.ssl_ctx, sock) fsock.setblocking(0) fsock.set_connect_state() ssl_async_handshake(fsock, self.hub, finish) else: fsock = sock finish()
def connect_callback(): if cancel_timer is not None: cancel_timer.cancel() self.hub.unregister(sock) def finish(): client.conn = Connection(fsock, ip) client.connected = True self.hub.schedule(lambda: self.wake()) if client.ssl_ctx: fsock = SSL.Connection(client.ssl_ctx, sock) fsock.setblocking(0) fsock.set_connect_state() ssl_async_handshake(fsock, self.hub, finish) else: fsock = sock finish()
def connect_callback(): if cancel_timer is not None: cancel_timer.cancel() self.hub.unregister(sock) def finish(): client.conn = Connection(fsock, ip) client.connected = True self.hub.schedule( lambda: self.wake() ) if client.ssl_ctx: fsock = SSL.Connection(client.ssl_ctx, sock) fsock.setblocking(0) fsock.set_connect_state() ssl_async_handshake(fsock, self.hub, finish) else: fsock = sock finish()
if code in (errno.EAGAIN, errno.EINTR): return raise sock.setblocking(0) def make_connection(): c = Connection(sock, addr) l = Loop(self.connection_handler, addr) l.connection_stack.append(c) runtime.current_app.add_loop(l) if self.ssl_ctx: sock = SSL.Connection(self.ssl_ctx, sock) sock.set_accept_state() sock.setblocking(0) ssl_async_handshake(sock, self.application.hub, make_connection) else: make_connection() class Thunk(object): def __init__(self, c): self.c = c def eval(self): return self.c() class UDPService(Service): '''A UDP service listening on a certain port, with a protocol implemented by a passed connection handler.
except socket.error, e: code, s = e if code in (errno.EAGAIN, errno.EINTR): return raise sock.setblocking(0) def make_connection(): c = Connection(sock, addr) l = Loop(self.connection_handler, addr) l.connection_stack.append(c) runtime.current_app.add_loop(l) if self.ssl_ctx: sock = SSL.Connection(self.ssl_ctx, sock) sock.set_accept_state() sock.setblocking(0) ssl_async_handshake(sock, self.application.hub, make_connection) else: make_connection() class UDPService(Service): '''A UDP service listening on a certain port, with a protocol implemented by a passed connection handler. ''' def __init__(self, connection_handler, port, iface=''): Service.__init__(self, connection_handler, port, iface) def bind_and_listen(self): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # unsure if the following two lines are necessary for UDP sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setblocking(0)