$OpenBSD: patch-Modules_socketmodule_c,v 1.2 2007/04/24 23:32:47 djm Exp $ --- Modules/socketmodule.c.orig Sat Mar 31 15:56:11 2007 +++ Modules/socketmodule.c Tue Apr 14 06:36:58 2009 @@ -73,9 +73,6 @@ Local naming conventions: #include "Python.h" #include "structmember.h" -#undef MAX -#define MAX(x, y) ((x) < (y) ? (y) : (x)) - /* Socket object documentation */ PyDoc_STRVAR(sock_doc, "socket([family[, type[, proto]]]) -> socket object\n\ @@ -161,7 +158,7 @@ shutdown(how) -- shut down traffic in one or both dire (this includes the getaddrinfo emulation) protect access with a lock. */ #if defined(WITH_THREAD) && (defined(__APPLE__) || \ (defined(__FreeBSD__) && __FreeBSD_version+0 < 503000) || \ - defined(__OpenBSD__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FabBSD__) \ defined(__VMS) || !defined(HAVE_GETADDRINFO)) #define USE_GETADDRINFO_LOCK #endif @@ -1921,12 +1918,18 @@ internal_connect(PySocketSockObject *s, struct sockadd 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; + /* 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) + else if (timeout == -1) { res = errno; /* had error */ + } else res = EWOULDBLOCK; /* timed out */ } @@ -3602,7 +3605,7 @@ socket_inet_aton(PyObject *self, PyObject *args) #if !defined(HAVE_INET_ATON) || defined(USE_INET_ATON_WEAKLINK) /* Have to use inet_addr() instead */ - unsigned long packed_addr; + int packed_addr; #endif char *ip_addr;