diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-04-09 08:27:25 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-04-09 08:27:25 (GMT) |
commit | ced117452585913395ceffd742c9dd7aeaf80630 (patch) | |
tree | 8648fd4acb1cca5834e4e269c66dfb4388c58a30 | |
parent | 88ed640fc7aec18c6148525801186264ebef8a75 (diff) | |
download | cpython-ced117452585913395ceffd742c9dd7aeaf80630.zip cpython-ced117452585913395ceffd742c9dd7aeaf80630.tar.gz cpython-ced117452585913395ceffd742c9dd7aeaf80630.tar.bz2 |
Issue #23618: Fix internal_select() for negative timeout (blocking socket) when
poll() is not available.
select() doesn't accept negative timeout, the timeout parameter must be NULL to
block on select().
-rw-r--r-- | Modules/socketmodule.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 8c5c36c..fd20b17 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -614,7 +614,7 @@ internal_select(PySocketSockObject *s, int writing, _PyTime_t interval, _PyTime_t ms; #else fd_set fds, efds; - struct timeval tv; + struct timeval tv, *tvp; #endif #ifdef WITH_THREAD @@ -650,7 +650,12 @@ internal_select(PySocketSockObject *s, int writing, _PyTime_t interval, n = poll(&pollfd, 1, (int)ms); Py_END_ALLOW_THREADS; #else - _PyTime_AsTimeval_noraise(interval, &tv, _PyTime_ROUND_CEILING); + if (interval >= 0) { + _PyTime_AsTimeval_noraise(interval, &tv, _PyTime_ROUND_CEILING); + tvp = &tv; + } + else + tvp = NULL; FD_ZERO(&fds); FD_SET(s->sock_fd, &fds); @@ -667,10 +672,10 @@ internal_select(PySocketSockObject *s, int writing, _PyTime_t interval, Py_BEGIN_ALLOW_THREADS; if (writing) n = select(Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int), - NULL, &fds, &efds, &tv); + NULL, &fds, &efds, tvp); else n = select(Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int), - &fds, NULL, &efds, &tv); + &fds, NULL, &efds, tvp); Py_END_ALLOW_THREADS; #endif |