summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2008-01-19 20:47:59 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2008-01-19 20:47:59 (GMT)
commit060e6855a802a9e9bf2e6905342f704f64a3a26d (patch)
tree4e7aacd975ced3b4a7c73c29e985983bc6cda79f /Modules/socketmodule.c
parente3979f776a3837716aa7e566e388332d85314ceb (diff)
downloadcpython-060e6855a802a9e9bf2e6905342f704f64a3a26d.zip
cpython-060e6855a802a9e9bf2e6905342f704f64a3a26d.tar.gz
cpython-060e6855a802a9e9bf2e6905342f704f64a3a26d.tar.bz2
Patch #1019808 from Federico Schwindt: Return correct socket error when
a default timeout has been set, by using getsockopt() to get the error condition (instead of trying another connect() call, which seems to be a Linuxism). 2.5 bugfix candidate, assuming no one reports any problems with this change.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 0ec4c0b..88d2a70 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1986,15 +1986,22 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
#else
if (s->sock_timeout > 0.0) {
- if (res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) {
- timeout = internal_select(s, 1);
- if (timeout == 0) {
- res = connect(s->sock_fd, addr, addrlen);
- if (res < 0 && errno == EISCONN)
- res = 0;
- }
- else if (timeout == -1)
- res = errno; /* had error */
+ if (res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) {
+ timeout = internal_select(s, 1);
+ if (timeout == 0) {
+ /* Bug #1019808: in case of an EINPROGRESS,
+ use getsockopt(SO_ERROR) to get the real
+ error. */
+ socklen_t res_size = sizeof res;
+ (void)getsockopt(s->sock_fd, SOL_SOCKET,
+ SO_ERROR, &res, &res_size);
+ if (res == EISCONN)
+ res = 0;
+ errno = res;
+ }
+ else if (timeout == -1) {
+ res = errno; /* had error */
+ }
else
res = EWOULDBLOCK; /* timed out */
}