[Python-checkins] r60101 - in python/trunk: Misc/ACKS Misc/NEWS Modules/socketmodule.c
andrew.kuchling
python-checkins at python.org
Sat Jan 19 21:47:59 CET 2008
Author: andrew.kuchling
Date: Sat Jan 19 21:47:59 2008
New Revision: 60101
Modified:
python/trunk/Misc/ACKS
python/trunk/Misc/NEWS
python/trunk/Modules/socketmodule.c
Log:
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.
Modified: python/trunk/Misc/ACKS
==============================================================================
--- python/trunk/Misc/ACKS (original)
+++ python/trunk/Misc/ACKS Sat Jan 19 21:47:59 2008
@@ -589,6 +589,7 @@
Sam Schulenburg
Stefan Schwarzer
Dietmar Schwertberger
+Federico Schwindt
Barry Scott
Steven Scott
Nick Seidenman
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sat Jan 19 21:47:59 2008
@@ -1120,6 +1120,9 @@
- Patch #1544279: Improve thread-safety of the socket module by moving
the sock_addr_t storage out of the socket object.
+- Patch #1019808: fix bug that causes an incorrect error to be returned
+ when a socket timeout is set and a connection attempt fails.
+
- Speed up function calls into the math module.
- Bug #1588217: don't parse "= " as a soft line break in binascii's
Modified: python/trunk/Modules/socketmodule.c
==============================================================================
--- python/trunk/Modules/socketmodule.c (original)
+++ python/trunk/Modules/socketmodule.c Sat Jan 19 21:47:59 2008
@@ -1986,15 +1986,22 @@
#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 */
}
More information about the Python-checkins
mailing list