def testWriteError(self): server = pulsar.create_socket('127.0.0.1:0') client = pulsar.create_connection(server.name, blocking=3) client_connection, address = server.accept() count = 0 while address is None and count < 10: count += 1 yield pulsar.NOT_DONE client_connection, address = server.accept() self.assertEqual(client.name, address) client_connection = pulsar.wrap_socket(client_connection) client_connection.send = mock.MagicMock(return_value=0) self.assertRaises(socket.error, client_connection.write, b'ciao') self.assertTrue(client_connection.closed)
def testWrite(self): server = pulsar.create_socket('127.0.0.1:0') self.assertEqual(server.accept(), (None, None)) client = pulsar.create_connection(server.name, blocking=3) client_connection, address = server.accept() count = 0 while address is None and count < 10: count += 1 yield pulsar.NOT_DONE client_connection, address = server.accept() self.assertEqual(client.address, address) client_connection = pulsar.wrap_socket(client_connection) self.assertEqual(client_connection.write(b''), 0) self.assertEqual(client_connection.write(b'ciao'), 4) client_connection.close() self.assertTrue(client_connection.closed) data = client.recv() self.assertEqual(data, b'ciao') data = client.recv() # The socket has shutdown self.assertEqual(data, b'')
def reconnect(self): if self.closed: sock = create_connection(self.remote_address, blocking=True) self._set_socket(sock)
def connect(cls, address, **kwargs): '''Create a new :class:`ClientSocket` connected at *address*.''' sock = create_connection(address) return cls(sock, address, **kwargs)