cpython: 7ed567ad8b4c (original) (raw)
Mercurial > cpython
changeset 95336:7ed567ad8b4c
Issue #23618: Enhance EINTR handling in socket.connect() Call PyErr_CheckSignals() immediatly if connect() or select() fails with EINTR in internal_connect(). Refactor also the code to limit indentaton and make it more readable. [#23618]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Tue, 31 Mar 2015 22:03:59 +0200 |
parents | 4fad2b9fc4e6 |
children | 87af6deb5d26 |
files | Modules/socketmodule.c |
diffstat | 1 files changed, 40 insertions(+), 38 deletions(-)[+] [-] Modules/socketmodule.c 78 |
line wrap: on
line diff
--- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -2461,52 +2461,54 @@ internal_connect(PySocketSockObject *s,
define TIMEOUT_ERR EWOULDBLOCK
Py_BEGIN_ALLOW_THREADS res = connect(s->sock_fd, addr, addrlen); Py_END_ALLOW_THREADS
- if (res < 0)
err = GET_ERROR;[](#l1.20)
- else
err = res;[](#l1.22)
- in_progress = (err == IN_PROGRESS_ERR);
- if (s->sock_timeout > 0 && in_progress && IS_SELECTABLE(s)) {
timeout = internal_connect_select(s);[](#l1.26)
if (timeout == 1) {[](#l1.28)
/* timed out */[](#l1.29)
err = TIMEOUT_ERR;[](#l1.30)
}[](#l1.31)
else if (timeout == 0) {[](#l1.32)
socklen_t res_size = sizeof res;[](#l1.33)
if (!getsockopt(s->sock_fd, SOL_SOCKET, SO_ERROR,[](#l1.34)
(void *)&res, &res_size)) {[](#l1.35)
if (res == EISCONN)[](#l1.36)
res = 0;[](#l1.37)
err = res;[](#l1.38)
}[](#l1.39)
else {[](#l1.40)
/* getsockopt() failed */[](#l1.41)
err = GET_ERROR;[](#l1.42)
}[](#l1.43)
}[](#l1.44)
else {[](#l1.45)
/* select() failed */[](#l1.46)
err = GET_ERROR;[](#l1.47)
}[](#l1.48)
- }
- *timeoutp = timeout;
- wait_connect = (s->sock_timeout > 0 && err == IN_PROGRESS_ERR
&& IS_SELECTABLE(s));[](#l1.64)
- if (!wait_connect)
return err;[](#l1.66)
- timeout = internal_connect_select(s);
- if (timeout == -1) {
/* select() failed */[](#l1.70)
err = GET_ERROR;[](#l1.71)
if (err == EINTR && PyErr_CheckSignals())[](#l1.72)
return -1;[](#l1.73)
return err;[](#l1.74)
- }
- if (timeout == 1) {
/* select() timed out */[](#l1.78)
*timeoutp = 1;[](#l1.79)
return TIMEOUT_ERR;[](#l1.80)
- }