Exemple #1
0
 def testUnixSocket(self):
     sock = pulsar.create_socket(self.tmpfile)
     self.assertEqual(sock.FAMILY, socket.AF_UNIX)
     self.assertEqual(sock.name, self.tmpfile)
     self.assertEqual(str(sock), 'unix:%s' % self.tmpfile)
     sock.close()
     self.assertFalse(os.path.exists(self.tmpfile))
Exemple #2
0
 def testSerialise(self):
     sock = pulsar.create_socket('127.0.0.1:0')
     v = pickle.dumps(sock)
     sock2 = pickle.loads(v)
     self.assertEqual(sock.name, sock2.name)
     sock.close()
     self.assertEqual(sock.name, None)
     self.assertTrue(sock.closed)
     self.assertEqual(sock.write(b'bla'), 0)
Exemple #3
0
 def make(cls, actor=None, bind=None, backlog=None, **kwargs):
     if actor is None:
         actor = get_actor()
     if not backlog:
         if actor:
             backlog = actor.cfg.backlog
         else:
             backlog = defaults.BACKLOG
     if bind:
         socket = create_socket(bind, backlog=backlog)
     else:
         socket = server_socket(backlog=backlog)
     return cls(actor, socket, **kwargs)
Exemple #4
0
 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)
Exemple #5
0
 def monitor_start(self, monitor):
     # if the platform does not support multiprocessing sockets set
     # the number of workers to 0.
     cfg = self.cfg
     if not self.socket_server_factory:
         raise TypeError('Socket server class not specified.')
     if not pulsar.platform.has_multiProcessSocket\
         or cfg.concurrency == 'thread':
         cfg.set('workers', 0)
     # Open the socket and bind to address
     address = self.cfg.address
     if address:
         socket = pulsar.create_socket(address, backlog=self.cfg.backlog)
     else:
         raise pulsar.ImproperlyConfigured('Could not open a socket. '
                                           'No address to bind to')
     self.logger.info('Listening on %s', socket)
     monitor.params.socket = socket
     self.address = socket.name
Exemple #6
0
 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'')