]> granicus.if.org Git - python/commitdiff
Issue #23834: Fix initial value of the socket timeout
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 6 Apr 2015 21:06:01 +0000 (23:06 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 6 Apr 2015 21:06:01 +0000 (23:06 +0200)
Use _PyTime_FromSeconds() to initialize the default socket timeout to -1
second, instead of -1 nanosecond which causes rounding issues in
internal_select().

Modules/socketmodule.c

index 5e267a4f29026948e27c4e47b6bd4a3afe066a23..604b9a82078fc4b214214522b7a1a726695944a3 100644 (file)
@@ -2292,7 +2292,7 @@ sock_setblocking(PySocketSockObject *s, PyObject *arg)
     if (block == -1 && PyErr_Occurred())
         return NULL;
 
-    s->sock_timeout = block ? -1 : 0;
+    s->sock_timeout = _PyTime_FromSeconds(block ? -1 : 0);
     internal_setblocking(s, block);
 
     Py_INCREF(Py_None);
@@ -4162,7 +4162,7 @@ sock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
     new = type->tp_alloc(type, 0);
     if (new != NULL) {
         ((PySocketSockObject *)new)->sock_fd = -1;
-        ((PySocketSockObject *)new)->sock_timeout = -1;
+        ((PySocketSockObject *)new)->sock_timeout = _PyTime_FromSeconds(-1);
         ((PySocketSockObject *)new)->errorhandler = &set_error;
     }
     return new;