def test_tcp1(self): self.server = pyuv.TCP(self.loop) self.server.bind(("0.0.0.0", TEST_PORT)) self.server.listen(self.on_connection) self.client = pyuv.TCP(self.loop) self.client.connect(("127.0.0.1", TEST_PORT), self.on_client_connection) self.loop.run()
def test_tcp_write_cancel(self): self.server = pyuv.TCP(self.loop) self.server.bind(("0.0.0.0", TEST_PORT)) self.server.listen(self.on_connection) self.client = pyuv.TCP(self.loop) self.client.connect(("127.0.0.1", TEST_PORT), self.on_client_connection) self.loop.run() self.assertEqual(self.write_cb_count, 1024)
def test_fileno(self): server = pyuv.TCP(self.loop) server.bind(("0.0.0.0", TEST_PORT)) self.check_fileno(server) server.listen(self.on_connection) client = pyuv.TCP(self.loop) client.connect(("127.0.0.1", TEST_PORT), self.on_client_connection) self.check_fileno(client) self.loop.run()
def test_tcp_write_saturate(self): if 'TRAVIS' in os.environ: self.skipTest("Test disabled on Travis") return self.server = pyuv.TCP(self.loop) self.server.bind(("0.0.0.0", TEST_PORT)) self.server.listen(self.on_connection) self.client = pyuv.TCP(self.loop) self.client.connect(("127.0.0.1", TEST_PORT), self.on_client_connection) self.loop.run()
def test_tcp_shutdown(self): self.shutdown_cb_called = 0 self.close_cb_called = 0 self.server = pyuv.TCP(self.loop) self.server.bind(("0.0.0.0", TEST_PORT)) self.server.listen(self.on_connection) self.client = pyuv.TCP(self.loop) self.client.connect(("127.0.0.1", TEST_PORT), self.on_client_connection) self.loop.run() self.assertEqual(self.shutdown_cb_called, 1) self.assertEqual(self.close_cb_called, 3)
def test_open(self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client = pyuv.TCP(self.loop) client.open(sock.fileno()) client.connect(("127.0.0.1", TEST_PORT), self.on_client_connect_error) self.loop.run() sock.close()
def on_connection(self, server, error): self.assertEqual(error, None) connection = pyuv.TCP(self.loop) server.accept(connection) while connection.write_queue_size == 0: connection.write(b"PING"*1000) connection.close(self.on_connection_close)
def _on_connection(self, handle, error): if error: logging.error('_on_connection: {}'.format(error)) return if type(self.socket) == pyuv.TCP: client = pyuv.TCP(self.loop) else: client = pyuv.Pipe(self.loop, True) self.socket.accept(client) if self.forward_address: self.on_connection(client) else: context = { 'buffer': [], 'stage': 0, 'header': b'', } client.start_read( lambda handle, data, error: self._socks5_read( handle, data, error, context ))
def test_tcp_flags(self): tcp = pyuv.TCP(self.loop) tcp.nodelay(True) tcp.keepalive(True, 60) tcp.simultaneous_accepts(True) tcp.close() self.loop.run()
def connectTCP(self, ip, port, factory, timeout=30, bindAddress=None): self.__log.debug("connectTCP: ip = {ip!r}".format(ip=ip)) # p = factory.buildProtocol(addr=(ip, port)) # tcp = pyuv.TCP(self._loop) p.transport = tcp # if bindAddress is not None: tcp.bind((bindAddress, port)) # def connect_cb(tcp_handle, error): if error: reason = pyuv.errno.strerror(error) self.__log.error(reason) p.connectionLost(reason=reason) else: p.connectionMade() # def read_cb(tcp_handle, data, error): if error: reason = pyuv.errno.strerror(error) self.__log.error(reason) p.connectionLost(reason=reason) else: p.dataReceived(data) # tcp.start_read(read_cb) # tcp.connect((ip, port), connect_cb) # return tcp
def __init__(self, server, endpoint): self.server = server loop = pyuv.Loop.default_loop() self.listenHandle = pyuv.TCP(loop) self.listenHandle.bind(endpoint) self.listenHandle.listen(self.onConnection)
def test_open(self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) loop = pyuv.Loop.default_loop() client = pyuv.TCP(loop) client.open(sock.fileno()) client.connect(("127.0.0.1", TEST_PORT), self.on_client_connect_error) loop.run()
def __init__(self, neighbor, local_address, forward_address=None): self.neighbor = neighbor self.loop = self.neighbor.manager.loop self.local_address = local_address self.forward_address = forward_address self.associaction = {} self.socket = pyuv.TCP(self.loop)
def test_client2(self): loop = pyuv.Loop.default_loop() client = pyuv.TCP(loop) self.assertFalse(client.readable) self.assertFalse(client.writable) client.close() loop.run()
def on_connection(self, server, error): self.assertEqual(error, None) client = pyuv.TCP(self.loop) server.accept(client) self.client_connections.append(client) client.start_read(self.on_client_connection_read) client.write(b"PING"+linesep)
def __init__(self, address=None, port=None): self._loop = pyuv.Loop() self._error = None self._data = None self._written = True self._connected = False self._timed_out = False self._timer = pyuv.Timer(self._loop) self._timeout_cb = self._on_timeout.__get__(self, UvStream) self._read_cb = self._on_read.__get__(self, UvStream) self._write_cb = self._on_write.__get__(self, UvStream) connect_cb = self._on_connect.__get__(self, UvStream) # Select the type of handle if port: # tcp self._stream = pyuv.TCP(self._loop) self._stream.connect((address, port), connect_cb) elif address: # named pipe or unix socket self._stream = pyuv.Pipe(self._loop) self._stream.connect(address, connect_cb) else: # stdin/stdout self._read_stream = pyuv.Pipe(self._loop) self._read_stream.open(sys.stdin.fileno()) self._write_stream = pyuv.Pipe(self._loop) self._write_stream.open(sys.stdout.fileno())
def on_connection(self, server, error): self.assertEqual(error, None) client = pyuv.TCP(pyuv.Loop.default_loop()) server.accept(client) self.client_connection = client client.start_read(self.on_client_connection_read) client.write(b"PING"+common.linesep)
def on_connection(self, server, error): self.assertEqual(error, None) client = pyuv.TCP(self.loop) server.accept(client) for x in range(1024): client.write(b"PING"*1000, self.on_client_write) client.close() server.close()
def on_connection(self, server, error): client = pyuv.TCP(pyuv.Loop.default_loop()) server.accept(client) self.client_connections.append(client) client.start_read(self.on_client_connection_read) client.writelines([ b"PING1", b"PING2", b"PING3", b"PING4", b"PING5", b"PING\x00\xFF6" ])
def test_family_unspec2(self): client = pyuv.TCP(self.loop, socket.AF_UNSPEC) with self.assertRaises(pyuv.error.TCPError): client.family client.bind(('::1', TEST_PORT)) self.assertEqual(client.family, socket.AF_INET6) client.close() self.loop.run()
def test_fromfd_inet6(self): client = pyuv.TCP(self.loop) client.bind(('::1', TEST_PORT)) sock = socket.fromfd(client.fileno(), client.family, socket.SOCK_STREAM) self.assertEqual(client.getsockname(), sock.getsockname()) client.close() sock.close() self.loop.run()
def on_connection(self, server, error): self.assertEqual(error, None) client = pyuv.TCP(pyuv.Loop.default_loop()) server.accept(client) self.client_connections.append(client) client.start_read(self.on_client_connection_read) data = memoryview(b"PING") client.write(data)
def on_connection(self, server, error): self.assertEqual(error, None) self.check_fileno(server) client = pyuv.TCP(self.loop) server.accept(client) self.check_fileno(client) client.close() server.close()
def connect(self, host, port): self._handle = pyuv.TCP(self._loop) self._handle.connect((host, int(port)), self._on_connected) self._handle.start_read(self._on_read) self._sigint_handler = pyuv.Signal(self._loop) self._sigint_handler.start(self._on_signal, signal.SIGINT) return
def handle_pending_client(self, server, err): client = pyuv.TCP(server.loop) server.accept(client) serverClient = ServerClient(client) self.clients.append(serverClient) # Begin the "recursive" read chain. client.start_read(serverClient.handle_data_available)
def start(self): self.server = pyuv.TCP(pyuv.Loop.default_loop()) self.server.bind(('0.0.0.0', 6379)) # Notice the tuple parameter self.server.listen(self.handle_pending_client) # Make sure to listen for SIGINT to happen so ^C works. self.sigint = pyuv.Signal(pyuv.Loop.default_loop()) self.sigint.start(self.handle_end_signal, signal.SIGINT)
def on_ipc_connection(self, handle, error): if self.local_conn_accepted: return conn = pyuv.TCP(self.loop) self.tcp_server.accept(conn) conn.close() self.tcp_server.close() self.local_conn_accepted = True
def test_tcp_flags(self): loop = pyuv.Loop.default_loop() tcp = pyuv.TCP(loop) tcp.nodelay(True) tcp.keepalive(True, 60) tcp.simultaneous_accepts(True) tcp.close() loop.run() self.assertTrue(True)
def on_ipc_connection(handle, error): global channel, connection_accepted, loop, tcp_server if connection_accepted: return conn = pyuv.TCP(loop) tcp_server.accept(conn) conn.close() channel.write(b"accepted_connection", on_channel_write) connection_accepted = True
def _on_connection(self, server, error): """ .. warning::Internal method. Connect to client on request """ client = pyuv.TCP(self.server.loop) self.server.accept(client) self.clients.append(client) client.start_read(self._stream)