Esempio n. 1
0
 def test_connector(self):
     s = concurrent.listen(("", 0))
     s.listen(3)
     self.s.add_address(s.getsockname())
     s.settimeout(0.4)
     client, _ = s.accept()
     uuid = "apa"
     client.send(uuid)
     wait_for(lambda: uuid in self.s._connectAddresses.values())
Esempio n. 2
0
 def __init__(self, listen, handler, connect_addresses=set(), connect_interval=30):
     if isinstance(listen, int):
         listen = ("0.0.0.0", listen)
     self.uuid = uuid()
     self.handler = handler
     self.connections = dict()
     self.connect_interval = connect_interval
     self._connectAddresses = dict((addr, True) for addr in connect_addresses)
     self._sock = concurrent.listen(listen)
     self._server = concurrent.spawn(concurrent.serve, self._sock, self._connectionWrapper)
     self._connectThread = concurrent.spawn(self._connector)
     logging.getLogger("syncer").info("Listening on %s", listen)
Esempio n. 3
0
    def test_connector_does_not_reconnect(self):
        s = concurrent.listen(("", 0))
        s.listen(3)
        self.s.add_address(s.getsockname())
        s.settimeout(0.2)
        client, _ = s.accept()

        assert_raises(concurrent.socket.error, s.accept)

        uuid = "apa"
        client.send(uuid)
        assert_raises(concurrent.socket.error, s.accept)

        client.shutdown(socket.SHUT_RDWR)
        client, _ = s.accept()
Esempio n. 4
0
 def __init__(self, name="Server"):
     super(Server, self).__init__()
     self.s = listen(('', 0), backlog=1)
     self.name = "Server"
     self.res = spawn(self.run)