]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #23834: Fix the default socket timeout
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 9 Apr 2015 08:23:12 +0000 (10:23 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 9 Apr 2015 08:23:12 +0000 (10:23 +0200)
Use -1 second by default, not -1 nanosecond.

Include/pytime.h
Modules/socketmodule.c

index bf0dcd86577fda0a549f5a15d2a5a508e41d2069..027c3d803a4122284b5f120aa46fa997ac12cfb6 100644 (file)
@@ -67,7 +67,12 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec(
 
 
 /* Create a timestamp from a number of seconds. */
-PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int ns);
+PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int seconds);
+
+/* Macro to create a timestamp from a number of seconds, no integer overflow.
+   Only use the macro for small values, prefer _PyTime_FromSeconds(). */
+#define _PYTIME_FROMSECONDS(seconds) \
+            ((_PyTime_t)(seconds) * (1000 * 1000 * 1000))
 
 /* Create a timestamp from a number of nanoseconds. */
 PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(PY_LONG_LONG ns);
index 1ecec5a3b9cb78a810a8d23c6f8e5581831087da..8c5c36cdc0dc3eec4610738cd158b96c60c108eb 100644 (file)
@@ -839,7 +839,8 @@ sock_call(PySocketSockObject *s,
 
 /* Initialize a new socket object. */
 
-static _PyTime_t defaulttimeout = -1; /* Default timeout for new sockets */
+/* Default timeout for new sockets */
+static _PyTime_t defaulttimeout = _PYTIME_FROMSECONDS(-1);
 
 static void
 init_sockobject(PySocketSockObject *s,