Issue #23618: Fix EINTR handling in socket.connect()
Call PyErr_CheckSignals() if connect(), select() or getsockopt() failed with EINTR.
This commit is contained in:
parent
c4e819a54f
commit
ee699e9d2b
@ -2502,6 +2502,9 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
|
|||||||
}
|
}
|
||||||
*timeoutp = timeout;
|
*timeoutp = timeout;
|
||||||
|
|
||||||
|
if (err == EINTR && PyErr_CheckSignals())
|
||||||
|
return -1;
|
||||||
|
|
||||||
assert(err >= 0);
|
assert(err >= 0);
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@ -2524,13 +2527,14 @@ sock_connect(PySocketSockObject *s, PyObject *addro)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout);
|
res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout);
|
||||||
|
if (res < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (timeout == 1) {
|
if (timeout == 1) {
|
||||||
PyErr_SetString(socket_timeout, "timed out");
|
PyErr_SetString(socket_timeout, "timed out");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (res < 0)
|
|
||||||
return NULL;
|
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
WSASetLastError(res);
|
WSASetLastError(res);
|
||||||
@ -2539,8 +2543,8 @@ sock_connect(PySocketSockObject *s, PyObject *addro)
|
|||||||
#endif
|
#endif
|
||||||
return s->errorhandler();
|
return s->errorhandler();
|
||||||
}
|
}
|
||||||
Py_INCREF(Py_None);
|
|
||||||
return Py_None;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(connect_doc,
|
PyDoc_STRVAR(connect_doc,
|
||||||
@ -2564,15 +2568,9 @@ sock_connect_ex(PySocketSockObject *s, PyObject *addro)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout);
|
res = internal_connect(s, SAS2SA(&addrbuf), addrlen, &timeout);
|
||||||
|
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return NULL;
|
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);
|
return PyLong_FromLong((long) res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user