def create_echo_server(address, actor): '''Starts an echo server on a newly spawn actor''' server = TcpServer(actor.event_loop, address[0], address[1], EchoServerProtocol) yield server.start_serving() actor.servers['echo'] = server actor.extra['echo-address'] = server.address
def __call__(self, actor): """Starts an echo server on a newly spawn actor""" server = TcpServer(partial(Connection, EchoServerProtocol), actor._loop, self.address) yield from server.start_serving() actor.servers["echo"] = server actor.extra["echo-address"] = server.address actor.bind_event("stopping", self._stop_server) return actor
def create_server(self, worker, sock, ssl=None): '''Create the Server Protocol which will listen for requests. It uses the :meth:`protocol_consumer` method as the protocol consumer factory.''' cfg = self.cfg server = TcpServer(worker.event_loop, sock=sock, consumer_factory=self.protocol_consumer(), max_connections=cfg.max_requests, timeout=cfg.keep_alive, name=self.name) for event in ('connection_made', 'pre_request', 'post_request', 'connection_lost'): callback = getattr(cfg, event) if callback != pass_through: server.bind_event(event, callback) server.start_serving(cfg.backlog, sslcontext=worker.params.ssl) return server
def __call__(self, actor): '''Starts an echo server on a newly spawn actor''' server = TcpServer(partial(Connection, EchoServerProtocol), actor._loop, self.address) yield from server.start_serving() actor.servers['echo'] = server actor.extra['echo-address'] = server.address actor.bind_event('stopping', self._stop_server) return actor
def __call__(self, actor): '''Starts an echo server on a newly spawn actor''' address = self.address server = TcpServer(actor.event_loop, address[0], address[1], EchoServerProtocol) yield server.start_serving() actor.servers['echo'] = server actor.extra['echo-address'] = server.address actor.bind_event('stopping', self._stop_server) yield actor
def test_echo_serve(self): loop = get_event_loop() server = TcpServer(loop, '127.0.0.1', 0, EchoServerProtocol) yield server.start_serving() sock = server.sock fn = sock.fileno() self.assertFalse(is_socket_closed(sock)) client = Echo() address = sock.getsockname() result = yield client.request(address, b'Hello!') self.assertEqual(result, b'Hello!') self.assertEqual(server.concurrent_connections, 1) result = yield client.request(address, b'ciao') self.assertEqual(result, b'ciao') self.assertEqual(server.concurrent_connections, 1) yield server.stop_serving() yield async_while(3, lambda: not is_socket_closed(sock)) self.assertTrue(is_socket_closed(sock))