Ejemplo n.º 1
0
    def test_already_connected(self):
        s = concurrent.connect(self.s.local_addr())
        s.send("apa")
        wait_for(lambda: "apa" in self.s.connections)

        s1 = concurrent.connect(self.s.local_addr())
        s1.send("apa")
        assert_equal(s1.recv(1024), "")
Ejemplo n.º 2
0
    def close(self):
        if self._sock:
            sock = self._sock
            self._sock = None
            sname = sock.getsockname()
            sock.close()

            # Connect to break possibly hung accept()-call
            try:
                concurrent.connect(sname)
            except socket.error:
                pass
        self.wait()
Ejemplo n.º 3
0
 def test_sessionTermination(self):
     s = concurrent.connect(self.s.local_addr())
     s.send("apa")
     wait_for(lambda: "apa" in self.s.connections)
     s.shutdown(socket.SHUT_WR)
     s.close()
     wait_for(lambda: "apa" not in self.s.connections)
Ejemplo n.º 4
0
 def _connect(self, tgt):
     m = self.HOST_PORT_RE.match(tgt)
     if m:
         tgt = (m.group(1), int(m.group(2)))
     if isinstance(tgt, tuple):
         family = socket.AF_INET
     else:
         family = socket.AF_UNIX
     self._socket = concurrent.connect(tgt, family)
Ejemplo n.º 5
0
def socket_pair():
    s = concurrent.socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(("", 0))
    try:
        s.listen(1)
        t = concurrent.spawn(s.accept)
        c1 = concurrent.connect(s.getsockname())
        c2, _ = t.wait()
        return c1, c2
    except:
        return None, None
    finally:
        s.close()
Ejemplo n.º 6
0
 def _connect(addr):
     try:
         return addr, concurrent.connect(addr)
     except Exception:
         return addr, None
Ejemplo n.º 7
0
 def connect(self, name="Syncer2"):
     db = DB(":memory:")
     s = concurrent.connect(self.s.local_addr())
     return SyncConnection(db, name, s, None)
Ejemplo n.º 8
0
 def test_connected(self):
     s = concurrent.connect(self.s.local_addr())
     s.send("apa")
     wait_for(lambda: "apa" in self.s.connections)
     s.close()
Ejemplo n.º 9
0
 def test_connect(self):
     s = concurrent.connect(self.s.local_addr())
     assert_is_not_none(s)
     s.send("apa")
     assert_equal(s.recv(1024), "apa")
     s.close()