Exemple #1
0
 def testSendall(self):
     # Test sendall() timeout
     with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
         socket_helper.bind_port(serv, self.localhost)
         serv.listen()
         self.sock.connect(serv.getsockname())
         # Send a lot of data in order to bypass buffering in the TCP stack.
         self._sock_operation(100, 1.5, 'sendall', b"X" * 200000)
Exemple #2
0
 def testSendto(self):
     # Test sendto() timeout
     with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
         socket_helper.bind_port(serv, self.localhost)
         serv.listen()
         self.sock.connect(serv.getsockname())
         # The address argument is ignored since we already connected.
         self._sock_operation(100, 1.5, 'sendto', b"X" * 200000,
                              serv.getsockname())
Exemple #3
0
 def __init__(self, event):
     threading.Thread.__init__(self)
     self.event = event
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.port = socket_helper.bind_port(self.sock)
     # This will be set if the client wants us to wait before echoing
     # data back.
     self.start_resend_event = None
Exemple #4
0
 def setUp(self):
     self.evt = threading.Event()
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.sock.settimeout(60)  # Safety net. Look issue 11812
     self.port = socket_helper.bind_port(self.sock)
     self.thread = threading.Thread(target=self.server, args=(self.evt, self.sock))
     self.thread.daemon = True
     self.thread.start()
     self.evt.wait()
Exemple #5
0
 def setUp(self):
     self.evt = threading.Event()
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.sock.settimeout(20)
     self.port = socket_helper.bind_port(self.sock)
     self.server_thread = threading.Thread(target=self.server)
     self.server_thread.daemon = True
     self.server_thread.start()
     # Wait for the server to be ready.
     self.evt.wait()
     self.evt.clear()
     self.old_port = ftplib.FTP.port
     ftplib.FTP.port = self.port
    def test_send(self):
        evt = threading.Event()
        sock = socket.socket()
        sock.settimeout(3)
        port = socket_helper.bind_port(sock)

        cap = BytesIO()
        args = (evt, cap, sock)
        t = threading.Thread(target=capture_server, args=args)
        t.start()
        try:
            # wait a little longer for the server to initialize (it sometimes
            # refuses connections on slow machines without this wait)
            time.sleep(0.2)

            data = b"Suppose there isn't a 16-ton weight?"
            d = dispatcherwithsend_noread()
            d.create_socket()
            d.connect((socket_helper.HOST, port))

            # give time for socket to connect
            time.sleep(0.1)

            d.send(data)
            d.send(data)
            d.send(b'\n')

            n = 1000
            while d.out_buffer and n > 0:
                asyncore.poll()
                n -= 1

            evt.wait()

            self.assertEqual(cap.getvalue(), data * 2)
        finally:
            threading_helper.join_thread(t)
Exemple #7
0
 def testRecvfromTimeout(self):
     # Test recvfrom() timeout
     # Prevent "Address already in use" socket exceptions
     socket_helper.bind_port(self.sock, self.localhost)
     self._sock_operation(1, 1.5, 'recvfrom', 1024)
Exemple #8
0
 def testAcceptTimeout(self):
     # Test accept() timeout
     socket_helper.bind_port(self.sock, self.localhost)
     self.sock.listen()
     self._sock_operation(1, 1.5, 'accept')
Exemple #9
0
 def test_bind_port(self):
     s = socket.socket()
     socket_helper.bind_port(s)
     s.listen()
     s.close()
Exemple #10
0
 def setUp(self):
     self.serv = SleepySocket(sleep=200,
                              family=socket.AF_INET,
                              type=socket.SOCK_STREAM)
     NewTimeoutTests.PORT = socket_helper.bind_port(self.serv)
     self.serv.listen()