[Python-checkins] cpython: Issue #23618: Fix internal_select() for negative timeout (blocking socket) when

victor.stinner python-checkins at python.org
Thu Apr 9 10:32:55 CEST 2015


https://hg.python.org/cpython/rev/bff88c866886
changeset:   95495:bff88c866886
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Apr 09 10:27:25 2015 +0200
summary:
  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().

files:
  Modules/socketmodule.c |  13 +++++++++----
  1 files changed, 9 insertions(+), 4 deletions(-)


diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -614,7 +614,7 @@
     _PyTime_t ms;
 #else
     fd_set fds, efds;
-    struct timeval tv;
+    struct timeval tv, *tvp;
 #endif
 
 #ifdef WITH_THREAD
@@ -650,7 +650,12 @@
     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 @@
     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
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list