]> granicus.if.org Git - python/commitdiff
Issue #23618: Fix internal_select() for negative timeout (blocking socket) when
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 9 Apr 2015 08:27:25 +0000 (10:27 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 9 Apr 2015 08:27:25 +0000 (10:27 +0200)
poll() is not available.

select() doesn't accept negative timeout, the timeout parameter must be NULL to
block on select().

Modules/socketmodule.c

index 8c5c36cdc0dc3eec4610738cd158b96c60c108eb..fd20b174d3c83a3418a249c286edbca1769a93c3 100644 (file)
@@ -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