Skip to content

Commit 88ed640

Browse files
committed
Issue python#23834: Fix the default socket timeout
Use -1 second by default, not -1 nanosecond.
1 parent da5cbe6 commit 88ed640

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

Include/pytime.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec(
6767

6868

6969
/* Create a timestamp from a number of seconds. */
70-
PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int ns);
70+
PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int seconds);
71+
72+
/* Macro to create a timestamp from a number of seconds, no integer overflow.
73+
Only use the macro for small values, prefer _PyTime_FromSeconds(). */
74+
#define _PYTIME_FROMSECONDS(seconds) \
75+
((_PyTime_t)(seconds) * (1000 * 1000 * 1000))
7176

7277
/* Create a timestamp from a number of nanoseconds. */
7378
PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(PY_LONG_LONG ns);

Modules/socketmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,8 @@ sock_call(PySocketSockObject *s,
839839

840840
/* Initialize a new socket object. */
841841

842-
static _PyTime_t defaulttimeout = -1; /* Default timeout for new sockets */
842+
/* Default timeout for new sockets */
843+
static _PyTime_t defaulttimeout = _PYTIME_FROMSECONDS(-1);
843844

844845
static void
845846
init_sockobject(PySocketSockObject *s,

0 commit comments

Comments
 (0)