--- fe-connect.c	2005-05-05 11:36:20.000000000 -0500
+++ /Users/agentm/Documents/Download/postgresql-8.0.3/src/interfaces/libpq/fe-connect.c	2005-06-26 16:52:36.000000000 -0500
@@ -1239,15 +1239,44 @@
 					 * Start/make connection.  This should not block,
 					 * since we are in nonblock mode.  If it does, well,
 					 * too bad.
+					 * "Too bad"? Uh- the code really guarantees that connect will not block, right?
 					 */
-			retry_connect:
 					if (connect(conn->sock, addr_cur->ai_addr,
 								addr_cur->ai_addrlen) < 0)
 					{
-						if (SOCK_ERRNO == EINTR)
-							/* Interrupted system call - just try again */
-							goto retry_connect;
-						if (SOCK_ERRNO == EINPROGRESS ||
+                                                  /* For an interrupted connect call- do not retry!
+						   * ref:http://www.opengroup.org/onlinepubs/009695399/functions/connect.html
+						   * An interrupt during connect in blocking mode 
+						   * wiill trigger the following block. The 
+						   * non-blocking code follows below this one.
+						   * However, if we aren't supposed to block,
+						   * just simulate EINPROGRESS event.
+						  */
+					  if (SOCK_ERRNO == EINTR)
+					    {
+					      int ret;
+					      if(conn->nonblocking)
+						{
+						  SOCK_ERRNO=EINPROGRESS; 
+						  //drops us into if statement below
+						}
+					      else //connection is blocking
+						{
+						  //poll on socket until it is writeable
+						  do 
+						    {
+						      fd_set writefds;
+						      
+						      FD_ZERO(&writefds);
+						      FD_SET(conn->sock,&writefds);
+						      errno=0;
+						      ret=select(conn->sock+1,NULL,&writefds,NULL,NULL);
+						    }
+						  while((ret<0 && SOCK_ERRNO==EINTR) || ret<1);
+						}
+					    }
+					  
+					  if (SOCK_ERRNO == EINPROGRESS ||
 							SOCK_ERRNO == EWOULDBLOCK ||
 							SOCK_ERRNO == 0)
 						{
