diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-05-10 17:19:13 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-05-10 17:19:13 (GMT) |
commit | 3cade9942e5e3cc6d185ee5c1b444498e297be02 (patch) | |
tree | 472cf36ec53e9a21ea524c620c06a9d376bd0256 /Modules | |
parent | 388196ed72fbac61eea511eefb36f8f94634a8b4 (diff) | |
parent | 1be815aac49bc0dc3937eb3a618fc9f1a6deb51a (diff) | |
download | cpython-3cade9942e5e3cc6d185ee5c1b444498e297be02.zip cpython-3cade9942e5e3cc6d185ee5c1b444498e297be02.tar.gz cpython-3cade9942e5e3cc6d185ee5c1b444498e297be02.tar.bz2 |
Issue #8498: In socket.accept(), allow to specify 0 as a backlog value in
order to accept exactly one connection. Patch by Daniel Evers.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/socketmodule.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 1631363..b05f089 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -2220,8 +2220,10 @@ sock_listen(PySocketSockObject *s, PyObject *arg) if (backlog == -1 && PyErr_Occurred()) return NULL; Py_BEGIN_ALLOW_THREADS - if (backlog < 1) - backlog = 1; + /* To avoid problems on systems that don't allow a negative backlog + * (which doesn't make sense anyway) we force a minimum value of 0. */ + if (backlog < 0) + backlog = 0; res = listen(s->sock_fd, backlog); Py_END_ALLOW_THREADS if (res < 0) @@ -2234,8 +2236,9 @@ PyDoc_STRVAR(listen_doc, "listen(backlog)\n\ \n\ Enable a server to accept connections. The backlog argument must be at\n\ -least 1; it specifies the number of unaccepted connection that the system\n\ -will allow before refusing new connections."); +least 0 (if it is lower, it is set to 0); it specifies the number of\n\ +unaccepted connections that the system will allow before refusing new\n\ +connections."); /* |