Mercurial > cpython-lru_cache-weakref
diff Modules/socketmodule.c @ 70011:48743ad2d2ef 2.7
Issue #8498: In socket.accept(), allow to specify 0 as a backlog value in
order to accept exactly one connection. Patch by Daniel Evers.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Tue, 10 May 2011 19:16:03 +0200 |
| parents | 7c3a20b5943a |
| children | dfe6f0a603d2 |
line wrap: on
line diff
--- a/Modules/socketmodule.c Tue May 10 00:39:02 2011 -0700 +++ b/Modules/socketmodule.c Tue May 10 19:16:03 2011 +0200 @@ -2244,8 +2244,10 @@ 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) @@ -2258,8 +2260,9 @@ "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."); #ifndef NO_DUP
