Issue #21566: Make use of socket.listen() default backlog.

This commit is contained in:
Charles-François Natali 2014-07-23 19:28:13 +01:00
parent 8518b79a8d
commit 6e20460dc6
18 changed files with 33 additions and 33 deletions

View File

@ -107,7 +107,7 @@ class ForkServer(object):
address = connection.arbitrary_address('AF_UNIX')
listener.bind(address)
os.chmod(address, 0o600)
listener.listen(100)
listener.listen()
# all client processes own the write end of the "alive" pipe;
# when they all terminate the read end becomes ready.

View File

@ -2543,7 +2543,7 @@ class _TestPicklingConnections(BaseTestCase):
l = socket.socket()
l.bind((test.support.HOST, 0))
l.listen(1)
l.listen()
conn.send(l.getsockname())
new_conn, addr = l.accept()
conn.send(new_conn)
@ -3190,7 +3190,7 @@ class TestWait(unittest.TestCase):
from multiprocessing.connection import wait
l = socket.socket()
l.bind((test.support.HOST, 0))
l.listen(4)
l.listen()
addr = l.getsockname()
readers = []
procs = []

View File

@ -37,7 +37,7 @@ if threading:
self.start_resend_event = None
def run(self):
self.sock.listen(1)
self.sock.listen()
self.event.set()
conn, client = self.sock.accept()
self.buffer = b""

View File

@ -428,7 +428,7 @@ class EventLoopTestsMixin:
listener = socket.socket()
listener.setblocking(False)
listener.bind(('127.0.0.1', 0))
listener.listen(1)
listener.listen()
client = socket.socket()
client.connect(listener.getsockname())

View File

@ -64,7 +64,7 @@ class crashingdummy:
# used when testing senders; just collects what it gets until newline is sent
def capture_server(evt, buf, serv):
try:
serv.listen(5)
serv.listen()
conn, addr = serv.accept()
except socket.timeout:
pass

View File

@ -44,7 +44,7 @@ class TestEPoll(unittest.TestCase):
def setUp(self):
self.serverSocket = socket.socket()
self.serverSocket.bind(('127.0.0.1', 0))
self.serverSocket.listen(1)
self.serverSocket.listen()
self.connections = [self.serverSocket]
def tearDown(self):

View File

@ -137,7 +137,7 @@ class DummyFTPHandler(asynchat.async_chat):
def cmd_pasv(self, arg):
with socket.socket() as sock:
sock.bind((self.socket.getsockname()[0], 0))
sock.listen(5)
sock.listen()
sock.settimeout(TIMEOUT)
ip, port = sock.getsockname()[:2]
ip = ip.replace('.', ','); p1 = port / 256; p2 = port % 256
@ -155,7 +155,7 @@ class DummyFTPHandler(asynchat.async_chat):
def cmd_epsv(self, arg):
with socket.socket(socket.AF_INET6) as sock:
sock.bind((self.socket.getsockname()[0], 0))
sock.listen(5)
sock.listen()
sock.settimeout(TIMEOUT)
port = sock.getsockname()[1]
self.push('229 entering extended passive mode (|||%d|)' %port)
@ -983,7 +983,7 @@ class TestTimeouts(TestCase):
# 1) when the connection is ready to be accepted.
# 2) when it is safe for the caller to close the connection
# 3) when we have closed the socket
self.sock.listen(5)
self.sock.listen()
# (1) Signal the caller that we are ready to accept the connection.
self.evt.set()
try:

View File

@ -919,7 +919,7 @@ class SourceAddressTest(TestCase):
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.port = support.bind_port(self.serv)
self.source_port = support.find_unused_port()
self.serv.listen(5)
self.serv.listen()
self.conn = None
def tearDown(self):
@ -951,7 +951,7 @@ class TimeoutTest(TestCase):
def setUp(self):
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
TimeoutTest.PORT = support.bind_port(self.serv)
self.serv.listen(5)
self.serv.listen()
def tearDown(self):
self.serv.close()

View File

@ -89,7 +89,7 @@ class TestKQueue(unittest.TestCase):
def test_queue_event(self):
serverSocket = socket.socket()
serverSocket.bind(('127.0.0.1', 0))
serverSocket.listen(1)
serverSocket.listen()
client = socket.socket()
client.setblocking(False)
try:

View File

@ -451,7 +451,7 @@ class TestTimeouts(TestCase):
del self.thread # Clear out any dangling Thread objects.
def server(self, evt, serv):
serv.listen(5)
serv.listen()
evt.set()
try:
conn, addr = serv.accept()

View File

@ -24,7 +24,7 @@ else:
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
with socket.socket(family, type, proto) as l:
l.bind((support.HOST, 0))
l.listen(3)
l.listen()
c = socket.socket(family, type, proto)
try:
c.connect(l.getsockname())

View File

@ -31,7 +31,7 @@ if sys.platform == 'darwin':
def server(evt, buf, serv):
serv.listen(5)
serv.listen()
evt.set()
try:
conn, addr = serv.accept()

View File

@ -72,7 +72,7 @@ class SocketTCPTest(unittest.TestCase):
def setUp(self):
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.port = support.bind_port(self.serv)
self.serv.listen(1)
self.serv.listen()
def tearDown(self):
self.serv.close()
@ -441,7 +441,7 @@ class SocketListeningTestMixin(SocketTestBase):
def setUp(self):
super().setUp()
self.serv.listen(1)
self.serv.listen()
class ThreadedSocketTestMixin(ThreadSafeCleanupTestCase, SocketTestBase,
@ -3784,7 +3784,7 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM |
socket.SOCK_NONBLOCK)
self.port = support.bind_port(self.serv)
self.serv.listen(1)
self.serv.listen()
# actual testing
start = time.time()
try:
@ -4559,7 +4559,7 @@ class TestLinuxAbstractNamespace(unittest.TestCase):
address = b"\x00python-test-hello\x00\xff"
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s1:
s1.bind(address)
s1.listen(1)
s1.listen()
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s2:
s2.connect(s1.getsockname())
with s1.accept()[0] as s3:
@ -4791,7 +4791,7 @@ class TIPCThreadableTest(unittest.TestCase, ThreadableTest):
srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE,
TIPC_LOWER, TIPC_UPPER)
self.srv.bind(srvaddr)
self.srv.listen(5)
self.srv.listen()
self.serverExplicitReady()
self.conn, self.connaddr = self.srv.accept()
self.addCleanup(self.conn.close)

View File

@ -1211,7 +1211,7 @@ class SSLErrorTests(unittest.TestCase):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
with socket.socket() as s:
s.bind(("127.0.0.1", 0))
s.listen(5)
s.listen()
c = socket.socket()
c.connect(s.getsockname())
c.setblocking(False)
@ -1736,7 +1736,7 @@ else:
def run(self):
self.sock.settimeout(0.05)
self.sock.listen(5)
self.sock.listen()
self.active = True
if self.flag:
# signal an event
@ -2162,7 +2162,7 @@ else:
# and sets Event `listener_gone` to let the main thread know
# the socket is gone.
def listener():
s.listen(5)
s.listen()
listener_ready.set()
newsock, addr = s.accept()
newsock.close()
@ -2590,7 +2590,7 @@ else:
finish = False
def serve():
server.listen(5)
server.listen()
started.set()
conns = []
while not finish:
@ -2647,7 +2647,7 @@ else:
peer = None
def serve():
nonlocal remote, peer
server.listen(5)
server.listen()
# Block on the accept and wait on the connection to close.
evt.set()
remote, peer = server.accept()

View File

@ -84,7 +84,7 @@ class TestSupport(unittest.TestCase):
def test_bind_port(self):
s = socket.socket()
support.bind_port(s)
s.listen(1)
s.listen()
s.close()
# Tests for temp_dir()

View File

@ -11,7 +11,7 @@ threading = support.import_module('threading')
HOST = support.HOST
def server(evt, serv):
serv.listen(5)
serv.listen()
evt.set()
try:
conn, addr = serv.accept()

View File

@ -243,14 +243,14 @@ class TCPTimeoutTestCase(TimeoutTestCase):
def testAcceptTimeout(self):
# Test accept() timeout
support.bind_port(self.sock, self.localhost)
self.sock.listen(5)
self.sock.listen()
self._sock_operation(1, 1.5, 'accept')
def testSend(self):
# Test send() timeout
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
support.bind_port(serv, self.localhost)
serv.listen(5)
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, 'send', b"X" * 200000)
@ -259,7 +259,7 @@ class TCPTimeoutTestCase(TimeoutTestCase):
# Test sendto() timeout
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
support.bind_port(serv, self.localhost)
serv.listen(5)
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,
@ -269,7 +269,7 @@ class TCPTimeoutTestCase(TimeoutTestCase):
# Test sendall() timeout
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
support.bind_port(serv, self.localhost)
serv.listen(5)
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)

View File

@ -1333,7 +1333,7 @@ class URLopener_Tests(unittest.TestCase):
# serv.settimeout(3)
# serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# serv.bind(("", 9093))
# serv.listen(5)
# serv.listen()
# try:
# conn, addr = serv.accept()
# conn.send("1 Hola mundo\n")