$OpenBSD: patch-Modules_socketmodule_c,v 1.2 2007/04/24 23:32:47 djm Exp $
--- Modules/socketmodule.c.orig	Sun Apr  1 04:56:11 2007
+++ Modules/socketmodule.c	Fri Apr 20 13:29:23 2007
@@ -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\
@@ -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;
 
