summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-31 19:28:42 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-31 19:28:42 (GMT)
commitee699e9d2b8dbac53ee897ddd456ec7399d703de (patch)
tree0ad72c945c0761c728107c2661e1b193b187846c /Modules
parentc4e819a54f95ffc761ccedb680a39ce869a4ec2b (diff)
downloadcpython-ee699e9d2b8dbac53ee897ddd456ec7399d703de.zip
cpython-ee699e9d2b8dbac53ee897ddd456ec7399d703de.tar.gz
cpython-ee699e9d2b8dbac53ee897ddd456ec7399d703de.tar.bz2
Issue #23618: Fix EINTR handling in socket.connect()
Call PyErr_CheckSignals() if connect(), select() or getsockopt() failed with EINTR.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 211e77b..6565187 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2502,6 +2502,9 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
}
*timeoutp = timeout;
+ if (err == EINTR && PyErr_CheckSignals())
+ return -1;
+
assert(err >= 0);
return err;
@@ -2524,13 +2527,14 @@ sock_connect(PySocketSockObject *s, PyObject *addro)
return NULL;
res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout);
+ if (res < 0)
+ return NULL;
if (timeout == 1) {
PyErr_SetString(socket_timeout, "timed out");
return NULL;
}
- if (res < 0)
- return NULL;
+
if (res != 0) {
#ifdef MS_WINDOWS
WSASetLastError(res);
@@ -2539,8 +2543,8 @@ sock_connect(PySocketSockObject *s, PyObject *addro)
#endif
return s->errorhandler();
}
- Py_INCREF(Py_None);
- return Py_None;
+
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(connect_doc,
@@ -2564,15 +2568,9 @@ sock_connect_ex(PySocketSockObject *s, PyObject *addro)
return NULL;
res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout);
-
if (res < 0)
return NULL;
- /* Signals are not errors (though they may raise exceptions). Adapted
- from PyErr_SetFromErrnoWithFilenameObject(). */
- if (res == EINTR && PyErr_CheckSignals())
- return NULL;
-
return PyLong_FromLong((long) res);
}