From ced117452585913395ceffd742c9dd7aeaf80630 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 9 Apr 2015 10:27:25 +0200 Subject: [PATCH] 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(). --- Modules/socketmodule.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 8c5c36cdc0d..fd20b174d3c 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