[Python-checkins] cpython: Issue #23834: Fix the default socket timeout

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


https://hg.python.org/cpython/rev/462680f4e8af
changeset:   95494:462680f4e8af
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Apr 09 10:23:12 2015 +0200
summary:
  Issue #23834: Fix the default socket timeout

Use -1 second by default, not -1 nanosecond.

files:
  Include/pytime.h       |  7 ++++++-
  Modules/socketmodule.c |  3 ++-
  2 files changed, 8 insertions(+), 2 deletions(-)


diff --git a/Include/pytime.h b/Include/pytime.h
--- a/Include/pytime.h
+++ b/Include/pytime.h
@@ -67,7 +67,12 @@
 
 
 /* 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);
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -839,7 +839,8 @@
 
 /* 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,

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


More information about the Python-checkins mailing list