Unverified Kaydet (Commit) 8702b67d authored tarafından Giampaolo Rodola's avatar Giampaolo Rodola Kaydeden (comit) GitHub

BPO-17561: set create_server backlog default to None (GH-12735)

It turns out doing socket.listen(0) does not equal to "choose a
reasonable default". It actually means "set backlog to 0".
As such set backlog=None as the default for socket.create_server.
Fixes the following BB failures:
https://github.com/python/cpython/pull/11784#issuecomment-481036369
Ref. BPO-1756, GH-11784.
üst 79b5d290
......@@ -595,7 +595,7 @@ The following functions all create :ref:`socket objects <socket-objects>`.
.. versionchanged:: 3.2
*source_address* was added.
.. function:: create_server(address, *, family=AF_INET, backlog=0, reuse_port=False, dualstack_ipv6=False)
.. function:: create_server(address, *, family=AF_INET, backlog=None, reuse_port=False, dualstack_ipv6=False)
Convenience function which creates a TCP socket bound to *address* (a 2-tuple
``(host, port)``) and return the socket object.
......
......@@ -745,7 +745,7 @@ def has_dualstack_ipv6():
return False
def create_server(address, *, family=AF_INET, backlog=0, reuse_port=False,
def create_server(address, *, family=AF_INET, backlog=None, reuse_port=False,
dualstack_ipv6=False):
"""Convenience function which creates a SOCK_STREAM type socket
bound to *address* (a 2-tuple (host, port)) and return the socket
......@@ -804,7 +804,10 @@ def create_server(address, *, family=AF_INET, backlog=0, reuse_port=False,
msg = '%s (while attempting to bind on address %r)' % \
(err.strerror, address)
raise error(err.errno, msg) from None
sock.listen(backlog)
if backlog is None:
sock.listen()
else:
sock.listen(backlog)
return sock
except error:
sock.close()
......
Set backlog=None as the default for socket.create_server.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment