Documentation
The documentation inconsistently describes when a default value is chosen for socket backlog.
Paragraph for socket.listen says "if not specified, a default reasonable value is chosen."
Paragraph for socket.create_server says "when 0 a default reasonable value is chosen."
Calling socket.create_server without passing a backlog argument calls socket.listen without backlog argument. CPython does try to pick a sensible backlog value.
|
if backlog is None: |
|
sock.listen() |
|
else: |
|
sock.listen(backlog) |
|
int backlog = Py_MIN(SOMAXCONN, 128); |
The behaviour is different when backlog=0. In that case, it seems the C implementation may pick a value. See, for example, https://pubs.opengroup.org/onlinepubs/009696799/functions/listen.html
Simplest fix is probably making the socket.create_server docs consistent with socket.listen: "if not specified, a default reasonable value is chosen". That would, however, ignore the backlog=0 behaviour and might prove surprising.
Linked PRs
Documentation
The documentation inconsistently describes when a default value is chosen for socket
backlog.Paragraph for socket.listen says "if not specified, a default reasonable value is chosen."
Paragraph for socket.create_server says "when 0 a default reasonable value is chosen."
Calling
socket.create_serverwithout passing a backlog argument callssocket.listenwithout backlog argument. CPython does try to pick a sensible backlog value.cpython/Lib/socket.py
Lines 936 to 939 in 53a54b7
cpython/Modules/socketmodule.c
Line 3564 in 53a54b7
The behaviour is different when
backlog=0. In that case, it seems the C implementation may pick a value. See, for example, https://pubs.opengroup.org/onlinepubs/009696799/functions/listen.htmlSimplest fix is probably making the
socket.create_serverdocs consistent withsocket.listen: "if not specified, a default reasonable value is chosen". That would, however, ignore thebacklog=0behaviour and might prove surprising.Linked PRs