Issue #21566: Make use of socket.listen() default backlog.
This commit is contained in:
parent
8518b79a8d
commit
6e20460dc6
|
@ -107,7 +107,7 @@ class ForkServer(object):
|
||||||
address = connection.arbitrary_address('AF_UNIX')
|
address = connection.arbitrary_address('AF_UNIX')
|
||||||
listener.bind(address)
|
listener.bind(address)
|
||||||
os.chmod(address, 0o600)
|
os.chmod(address, 0o600)
|
||||||
listener.listen(100)
|
listener.listen()
|
||||||
|
|
||||||
# all client processes own the write end of the "alive" pipe;
|
# all client processes own the write end of the "alive" pipe;
|
||||||
# when they all terminate the read end becomes ready.
|
# when they all terminate the read end becomes ready.
|
||||||
|
|
|
@ -2543,7 +2543,7 @@ class _TestPicklingConnections(BaseTestCase):
|
||||||
|
|
||||||
l = socket.socket()
|
l = socket.socket()
|
||||||
l.bind((test.support.HOST, 0))
|
l.bind((test.support.HOST, 0))
|
||||||
l.listen(1)
|
l.listen()
|
||||||
conn.send(l.getsockname())
|
conn.send(l.getsockname())
|
||||||
new_conn, addr = l.accept()
|
new_conn, addr = l.accept()
|
||||||
conn.send(new_conn)
|
conn.send(new_conn)
|
||||||
|
@ -3190,7 +3190,7 @@ class TestWait(unittest.TestCase):
|
||||||
from multiprocessing.connection import wait
|
from multiprocessing.connection import wait
|
||||||
l = socket.socket()
|
l = socket.socket()
|
||||||
l.bind((test.support.HOST, 0))
|
l.bind((test.support.HOST, 0))
|
||||||
l.listen(4)
|
l.listen()
|
||||||
addr = l.getsockname()
|
addr = l.getsockname()
|
||||||
readers = []
|
readers = []
|
||||||
procs = []
|
procs = []
|
||||||
|
|
|
@ -37,7 +37,7 @@ if threading:
|
||||||
self.start_resend_event = None
|
self.start_resend_event = None
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.sock.listen(1)
|
self.sock.listen()
|
||||||
self.event.set()
|
self.event.set()
|
||||||
conn, client = self.sock.accept()
|
conn, client = self.sock.accept()
|
||||||
self.buffer = b""
|
self.buffer = b""
|
||||||
|
|
|
@ -428,7 +428,7 @@ class EventLoopTestsMixin:
|
||||||
listener = socket.socket()
|
listener = socket.socket()
|
||||||
listener.setblocking(False)
|
listener.setblocking(False)
|
||||||
listener.bind(('127.0.0.1', 0))
|
listener.bind(('127.0.0.1', 0))
|
||||||
listener.listen(1)
|
listener.listen()
|
||||||
client = socket.socket()
|
client = socket.socket()
|
||||||
client.connect(listener.getsockname())
|
client.connect(listener.getsockname())
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ class crashingdummy:
|
||||||
# used when testing senders; just collects what it gets until newline is sent
|
# used when testing senders; just collects what it gets until newline is sent
|
||||||
def capture_server(evt, buf, serv):
|
def capture_server(evt, buf, serv):
|
||||||
try:
|
try:
|
||||||
serv.listen(5)
|
serv.listen()
|
||||||
conn, addr = serv.accept()
|
conn, addr = serv.accept()
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -44,7 +44,7 @@ class TestEPoll(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.serverSocket = socket.socket()
|
self.serverSocket = socket.socket()
|
||||||
self.serverSocket.bind(('127.0.0.1', 0))
|
self.serverSocket.bind(('127.0.0.1', 0))
|
||||||
self.serverSocket.listen(1)
|
self.serverSocket.listen()
|
||||||
self.connections = [self.serverSocket]
|
self.connections = [self.serverSocket]
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
|
|
@ -137,7 +137,7 @@ class DummyFTPHandler(asynchat.async_chat):
|
||||||
def cmd_pasv(self, arg):
|
def cmd_pasv(self, arg):
|
||||||
with socket.socket() as sock:
|
with socket.socket() as sock:
|
||||||
sock.bind((self.socket.getsockname()[0], 0))
|
sock.bind((self.socket.getsockname()[0], 0))
|
||||||
sock.listen(5)
|
sock.listen()
|
||||||
sock.settimeout(TIMEOUT)
|
sock.settimeout(TIMEOUT)
|
||||||
ip, port = sock.getsockname()[:2]
|
ip, port = sock.getsockname()[:2]
|
||||||
ip = ip.replace('.', ','); p1 = port / 256; p2 = port % 256
|
ip = ip.replace('.', ','); p1 = port / 256; p2 = port % 256
|
||||||
|
@ -155,7 +155,7 @@ class DummyFTPHandler(asynchat.async_chat):
|
||||||
def cmd_epsv(self, arg):
|
def cmd_epsv(self, arg):
|
||||||
with socket.socket(socket.AF_INET6) as sock:
|
with socket.socket(socket.AF_INET6) as sock:
|
||||||
sock.bind((self.socket.getsockname()[0], 0))
|
sock.bind((self.socket.getsockname()[0], 0))
|
||||||
sock.listen(5)
|
sock.listen()
|
||||||
sock.settimeout(TIMEOUT)
|
sock.settimeout(TIMEOUT)
|
||||||
port = sock.getsockname()[1]
|
port = sock.getsockname()[1]
|
||||||
self.push('229 entering extended passive mode (|||%d|)' %port)
|
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.
|
# 1) when the connection is ready to be accepted.
|
||||||
# 2) when it is safe for the caller to close the connection
|
# 2) when it is safe for the caller to close the connection
|
||||||
# 3) when we have closed the socket
|
# 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.
|
# (1) Signal the caller that we are ready to accept the connection.
|
||||||
self.evt.set()
|
self.evt.set()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -919,7 +919,7 @@ class SourceAddressTest(TestCase):
|
||||||
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.port = support.bind_port(self.serv)
|
self.port = support.bind_port(self.serv)
|
||||||
self.source_port = support.find_unused_port()
|
self.source_port = support.find_unused_port()
|
||||||
self.serv.listen(5)
|
self.serv.listen()
|
||||||
self.conn = None
|
self.conn = None
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -951,7 +951,7 @@ class TimeoutTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
TimeoutTest.PORT = support.bind_port(self.serv)
|
TimeoutTest.PORT = support.bind_port(self.serv)
|
||||||
self.serv.listen(5)
|
self.serv.listen()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.serv.close()
|
self.serv.close()
|
||||||
|
|
|
@ -89,7 +89,7 @@ class TestKQueue(unittest.TestCase):
|
||||||
def test_queue_event(self):
|
def test_queue_event(self):
|
||||||
serverSocket = socket.socket()
|
serverSocket = socket.socket()
|
||||||
serverSocket.bind(('127.0.0.1', 0))
|
serverSocket.bind(('127.0.0.1', 0))
|
||||||
serverSocket.listen(1)
|
serverSocket.listen()
|
||||||
client = socket.socket()
|
client = socket.socket()
|
||||||
client.setblocking(False)
|
client.setblocking(False)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -451,7 +451,7 @@ class TestTimeouts(TestCase):
|
||||||
del self.thread # Clear out any dangling Thread objects.
|
del self.thread # Clear out any dangling Thread objects.
|
||||||
|
|
||||||
def server(self, evt, serv):
|
def server(self, evt, serv):
|
||||||
serv.listen(5)
|
serv.listen()
|
||||||
evt.set()
|
evt.set()
|
||||||
try:
|
try:
|
||||||
conn, addr = serv.accept()
|
conn, addr = serv.accept()
|
||||||
|
|
|
@ -24,7 +24,7 @@ else:
|
||||||
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
|
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
|
||||||
with socket.socket(family, type, proto) as l:
|
with socket.socket(family, type, proto) as l:
|
||||||
l.bind((support.HOST, 0))
|
l.bind((support.HOST, 0))
|
||||||
l.listen(3)
|
l.listen()
|
||||||
c = socket.socket(family, type, proto)
|
c = socket.socket(family, type, proto)
|
||||||
try:
|
try:
|
||||||
c.connect(l.getsockname())
|
c.connect(l.getsockname())
|
||||||
|
|
|
@ -31,7 +31,7 @@ if sys.platform == 'darwin':
|
||||||
|
|
||||||
|
|
||||||
def server(evt, buf, serv):
|
def server(evt, buf, serv):
|
||||||
serv.listen(5)
|
serv.listen()
|
||||||
evt.set()
|
evt.set()
|
||||||
try:
|
try:
|
||||||
conn, addr = serv.accept()
|
conn, addr = serv.accept()
|
||||||
|
|
|
@ -72,7 +72,7 @@ class SocketTCPTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.port = support.bind_port(self.serv)
|
self.port = support.bind_port(self.serv)
|
||||||
self.serv.listen(1)
|
self.serv.listen()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.serv.close()
|
self.serv.close()
|
||||||
|
@ -441,7 +441,7 @@ class SocketListeningTestMixin(SocketTestBase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.serv.listen(1)
|
self.serv.listen()
|
||||||
|
|
||||||
|
|
||||||
class ThreadedSocketTestMixin(ThreadSafeCleanupTestCase, SocketTestBase,
|
class ThreadedSocketTestMixin(ThreadSafeCleanupTestCase, SocketTestBase,
|
||||||
|
@ -3784,7 +3784,7 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
|
||||||
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM |
|
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM |
|
||||||
socket.SOCK_NONBLOCK)
|
socket.SOCK_NONBLOCK)
|
||||||
self.port = support.bind_port(self.serv)
|
self.port = support.bind_port(self.serv)
|
||||||
self.serv.listen(1)
|
self.serv.listen()
|
||||||
# actual testing
|
# actual testing
|
||||||
start = time.time()
|
start = time.time()
|
||||||
try:
|
try:
|
||||||
|
@ -4559,7 +4559,7 @@ class TestLinuxAbstractNamespace(unittest.TestCase):
|
||||||
address = b"\x00python-test-hello\x00\xff"
|
address = b"\x00python-test-hello\x00\xff"
|
||||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s1:
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s1:
|
||||||
s1.bind(address)
|
s1.bind(address)
|
||||||
s1.listen(1)
|
s1.listen()
|
||||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s2:
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s2:
|
||||||
s2.connect(s1.getsockname())
|
s2.connect(s1.getsockname())
|
||||||
with s1.accept()[0] as s3:
|
with s1.accept()[0] as s3:
|
||||||
|
@ -4791,7 +4791,7 @@ class TIPCThreadableTest(unittest.TestCase, ThreadableTest):
|
||||||
srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE,
|
srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE,
|
||||||
TIPC_LOWER, TIPC_UPPER)
|
TIPC_LOWER, TIPC_UPPER)
|
||||||
self.srv.bind(srvaddr)
|
self.srv.bind(srvaddr)
|
||||||
self.srv.listen(5)
|
self.srv.listen()
|
||||||
self.serverExplicitReady()
|
self.serverExplicitReady()
|
||||||
self.conn, self.connaddr = self.srv.accept()
|
self.conn, self.connaddr = self.srv.accept()
|
||||||
self.addCleanup(self.conn.close)
|
self.addCleanup(self.conn.close)
|
||||||
|
|
|
@ -1211,7 +1211,7 @@ class SSLErrorTests(unittest.TestCase):
|
||||||
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
|
||||||
with socket.socket() as s:
|
with socket.socket() as s:
|
||||||
s.bind(("127.0.0.1", 0))
|
s.bind(("127.0.0.1", 0))
|
||||||
s.listen(5)
|
s.listen()
|
||||||
c = socket.socket()
|
c = socket.socket()
|
||||||
c.connect(s.getsockname())
|
c.connect(s.getsockname())
|
||||||
c.setblocking(False)
|
c.setblocking(False)
|
||||||
|
@ -1736,7 +1736,7 @@ else:
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.sock.settimeout(0.05)
|
self.sock.settimeout(0.05)
|
||||||
self.sock.listen(5)
|
self.sock.listen()
|
||||||
self.active = True
|
self.active = True
|
||||||
if self.flag:
|
if self.flag:
|
||||||
# signal an event
|
# signal an event
|
||||||
|
@ -2162,7 +2162,7 @@ else:
|
||||||
# and sets Event `listener_gone` to let the main thread know
|
# and sets Event `listener_gone` to let the main thread know
|
||||||
# the socket is gone.
|
# the socket is gone.
|
||||||
def listener():
|
def listener():
|
||||||
s.listen(5)
|
s.listen()
|
||||||
listener_ready.set()
|
listener_ready.set()
|
||||||
newsock, addr = s.accept()
|
newsock, addr = s.accept()
|
||||||
newsock.close()
|
newsock.close()
|
||||||
|
@ -2590,7 +2590,7 @@ else:
|
||||||
finish = False
|
finish = False
|
||||||
|
|
||||||
def serve():
|
def serve():
|
||||||
server.listen(5)
|
server.listen()
|
||||||
started.set()
|
started.set()
|
||||||
conns = []
|
conns = []
|
||||||
while not finish:
|
while not finish:
|
||||||
|
@ -2647,7 +2647,7 @@ else:
|
||||||
peer = None
|
peer = None
|
||||||
def serve():
|
def serve():
|
||||||
nonlocal remote, peer
|
nonlocal remote, peer
|
||||||
server.listen(5)
|
server.listen()
|
||||||
# Block on the accept and wait on the connection to close.
|
# Block on the accept and wait on the connection to close.
|
||||||
evt.set()
|
evt.set()
|
||||||
remote, peer = server.accept()
|
remote, peer = server.accept()
|
||||||
|
|
|
@ -84,7 +84,7 @@ class TestSupport(unittest.TestCase):
|
||||||
def test_bind_port(self):
|
def test_bind_port(self):
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
support.bind_port(s)
|
support.bind_port(s)
|
||||||
s.listen(1)
|
s.listen()
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
# Tests for temp_dir()
|
# Tests for temp_dir()
|
||||||
|
|
|
@ -11,7 +11,7 @@ threading = support.import_module('threading')
|
||||||
HOST = support.HOST
|
HOST = support.HOST
|
||||||
|
|
||||||
def server(evt, serv):
|
def server(evt, serv):
|
||||||
serv.listen(5)
|
serv.listen()
|
||||||
evt.set()
|
evt.set()
|
||||||
try:
|
try:
|
||||||
conn, addr = serv.accept()
|
conn, addr = serv.accept()
|
||||||
|
|
|
@ -243,14 +243,14 @@ class TCPTimeoutTestCase(TimeoutTestCase):
|
||||||
def testAcceptTimeout(self):
|
def testAcceptTimeout(self):
|
||||||
# Test accept() timeout
|
# Test accept() timeout
|
||||||
support.bind_port(self.sock, self.localhost)
|
support.bind_port(self.sock, self.localhost)
|
||||||
self.sock.listen(5)
|
self.sock.listen()
|
||||||
self._sock_operation(1, 1.5, 'accept')
|
self._sock_operation(1, 1.5, 'accept')
|
||||||
|
|
||||||
def testSend(self):
|
def testSend(self):
|
||||||
# Test send() timeout
|
# Test send() timeout
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
|
||||||
support.bind_port(serv, self.localhost)
|
support.bind_port(serv, self.localhost)
|
||||||
serv.listen(5)
|
serv.listen()
|
||||||
self.sock.connect(serv.getsockname())
|
self.sock.connect(serv.getsockname())
|
||||||
# Send a lot of data in order to bypass buffering in the TCP stack.
|
# Send a lot of data in order to bypass buffering in the TCP stack.
|
||||||
self._sock_operation(100, 1.5, 'send', b"X" * 200000)
|
self._sock_operation(100, 1.5, 'send', b"X" * 200000)
|
||||||
|
@ -259,7 +259,7 @@ class TCPTimeoutTestCase(TimeoutTestCase):
|
||||||
# Test sendto() timeout
|
# Test sendto() timeout
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
|
||||||
support.bind_port(serv, self.localhost)
|
support.bind_port(serv, self.localhost)
|
||||||
serv.listen(5)
|
serv.listen()
|
||||||
self.sock.connect(serv.getsockname())
|
self.sock.connect(serv.getsockname())
|
||||||
# The address argument is ignored since we already connected.
|
# The address argument is ignored since we already connected.
|
||||||
self._sock_operation(100, 1.5, 'sendto', b"X" * 200000,
|
self._sock_operation(100, 1.5, 'sendto', b"X" * 200000,
|
||||||
|
@ -269,7 +269,7 @@ class TCPTimeoutTestCase(TimeoutTestCase):
|
||||||
# Test sendall() timeout
|
# Test sendall() timeout
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
|
||||||
support.bind_port(serv, self.localhost)
|
support.bind_port(serv, self.localhost)
|
||||||
serv.listen(5)
|
serv.listen()
|
||||||
self.sock.connect(serv.getsockname())
|
self.sock.connect(serv.getsockname())
|
||||||
# Send a lot of data in order to bypass buffering in the TCP stack.
|
# Send a lot of data in order to bypass buffering in the TCP stack.
|
||||||
self._sock_operation(100, 1.5, 'sendall', b"X" * 200000)
|
self._sock_operation(100, 1.5, 'sendall', b"X" * 200000)
|
||||||
|
|
|
@ -1333,7 +1333,7 @@ class URLopener_Tests(unittest.TestCase):
|
||||||
# serv.settimeout(3)
|
# serv.settimeout(3)
|
||||||
# serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
# serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
# serv.bind(("", 9093))
|
# serv.bind(("", 9093))
|
||||||
# serv.listen(5)
|
# serv.listen()
|
||||||
# try:
|
# try:
|
||||||
# conn, addr = serv.accept()
|
# conn, addr = serv.accept()
|
||||||
# conn.send("1 Hola mundo\n")
|
# conn.send("1 Hola mundo\n")
|
||||||
|
|
Loading…
Reference in New Issue