コード例 #1
0
    def test_unix_abort(self):
        item = mkdtemp()

        try:
            url = f'unix://{item}/socket.sock'
            with Transport.from_url(url + '#bind') as s, Transport.from_url(url) as c:
                c.send(Packet(url, b'123'))

                c.close()

                for x in s.read():
                    break
                else:
                    raise ValueError('asd')

                try:
                    for _ in s.read():
                        pass
                except ConnectionAbortedError:
                    pass

                self.assertEqual(0, len(s._fd_clients))

                s.send(Packet(x.addr, x.data + b'__rep'))
        finally:
            shutil.rmtree(item)
コード例 #2
0
ファイル: loop.py プロジェクト: andreycizov/python-xrpc
    def send(self, idx: int, packet: RPCPacketRaw):
        chan = self.transports[idx]

        log_tr_net_pkt_out.debug('%s %s %s', chan.origin, packet.addr,
                                 packet.packet)

        raw_packet = Packet(packet.addr, packet.packet.pack())

        chan.send(raw_packet)
コード例 #3
0
    def test_max_sendto(self):
        S_ADDR = 'udp://0.0.0.0:23454'
        ATTEMPTS = 5
        with Transport.from_url(S_ADDR) as ts, Transport.from_url('udp://') as tc:
            for i in [1, 100, 1000, 10000, 50000] + [2**16-1000]:
                for y in range(ATTEMPTS):
                    pkt = Packet(S_ADDR, b'\x00' * i)
                    tc.send(pkt)

                    select_helper([ts.fd], max_wait=1.)

                    for pkt2 in ts.read():
                        pass
コード例 #4
0
    def test_unix(self):
        item = mkdtemp()

        try:
            url = f'unix://{item}/socket.sock'
            with Transport.from_url(url + '#bind') as s, Transport.from_url(url) as c:
                c.send(Packet(url, b'123'))

                for x in s.read():
                    break
                else:
                    raise ValueError('asd')

                s.send(Packet(x.addr, x.data + b'__rep'))

                for x in c.read():
                    break
                else:
                    raise ValueError('asd')

                self.assertEqual(b'123__rep', x.data)
        finally:
            shutil.rmtree(item)
コード例 #5
0
    def test_unix_autopath(self):

        url = 'unix://'

        with Transport.from_url(url + '#bind') as s:
            with Transport.from_url(s.origin) as c:
                pkt = Packet(s.origin, b'asd')
                c.send(pkt)

                for x in s.read(select_helper(s.fds)):
                    pkt_addr = urlparse(pkt.addr)
                    pkt_addr = urlunparse(pkt_addr._replace(netloc='0'))
                    pkt = replace(pkt, addr=pkt_addr)
                    self.assertEqual(pkt, x)
コード例 #6
0
 def test_sendto_url(self):
     with Transport.from_url('udp://0.0.0.0:23454') as t:
         t.send(Packet('udp://127.0.0.1:23453', b''))
コード例 #7
0
 def test_unknown_hostname(self):
     with Transport.from_url('udp://0.0.0.0') as t:
         t.send(Packet('udp://unknown_hostname:234', b'123'))
コード例 #8
0
    def signal_handler(self, sig, frame):
        self.logger('hdlr.x').info('%s %s', sig, frame)

        with Transport.from_url(self.path_unix) as t:
            sig = str(sig).encode()
            t.send(Packet(self.path_unix, sig))