I started a thread on the general list so read that for more info.

http://www.postgresql.org/message-id/520a6e55.40...@cchtml.com

I'm also going to submit the patch to CommitFest.

Thanks,
Michael
>From bb79da0013d5169b4530df28ece0c296004d1db4 Mon Sep 17 00:00:00 2001
From: Michael Cronenworth <m...@cchtml.com>
Date: Fri, 16 Aug 2013 18:50:28 -0500
Subject: [PATCH] libpq: Fix Windows socket error checking for MinGW

---
 src/interfaces/libpq/fe-connect.c | 12 ++++++++----
 src/interfaces/libpq/fe-misc.c    | 32 ++++++++++++++++++++++++++++++++
 src/interfaces/libpq/fe-secure.c  | 16 ++++++++++++++++
 3 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 18fcb0c..3693245 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -1779,11 +1779,15 @@ keep_going:						/* We will come back to here until there is
 					if (connect(conn->sock, addr_cur->ai_addr,
 								addr_cur->ai_addrlen) < 0)
 					{
-						if (SOCK_ERRNO == EINPROGRESS ||
-#ifdef WIN32
-							SOCK_ERRNO == EWOULDBLOCK ||
+#ifndef WIN32
+ 						if (SOCK_ERRNO == EINPROGRESS ||
+ 							SOCK_ERRNO == EWOULDBLOCK ||
+ 							SOCK_ERRNO == EINTR)
+#else
+						if (SOCK_ERRNO == WSAEINPROGRESS ||
+							SOCK_ERRNO == WSAEWOULDBLOCK ||
+							SOCK_ERRNO == WSAEINTR)
 #endif
-							SOCK_ERRNO == EINTR)
 						{
 							/*
 							 * This is fine - we're in non-blocking mode, and
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 6be3249..112cd12 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -655,7 +655,11 @@ retry3:
 						  conn->inBufSize - conn->inEnd);
 	if (nread < 0)
 	{
+#ifndef WIN32
 		if (SOCK_ERRNO == EINTR)
+#else
+		if (SOCK_ERRNO == WSAEINTR)
+#endif
 			goto retry3;
 		/* Some systems return EAGAIN/EWOULDBLOCK for no data */
 #ifdef EAGAIN
@@ -663,12 +667,20 @@ retry3:
 			return someread;
 #endif
 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
+#ifndef WIN32
 		if (SOCK_ERRNO == EWOULDBLOCK)
+#else
+		if (SOCK_ERRNO == WSAEWOULDBLOCK)
+#endif
 			return someread;
 #endif
 		/* We might get ECONNRESET here if using TCP and backend died */
 #ifdef ECONNRESET
+#ifndef WIN32
 		if (SOCK_ERRNO == ECONNRESET)
+#else
+		if (SOCK_ERRNO == WSAECONNRESET)
+#endif
 			goto definitelyFailed;
 #endif
 		/* pqsecure_read set the error message for us */
@@ -748,7 +760,11 @@ retry4:
 						  conn->inBufSize - conn->inEnd);
 	if (nread < 0)
 	{
+#ifndef WIN32
 		if (SOCK_ERRNO == EINTR)
+#else
+		if (SOCK_ERRNO == WSAEINTR)
+#endif
 			goto retry4;
 		/* Some systems return EAGAIN/EWOULDBLOCK for no data */
 #ifdef EAGAIN
@@ -756,12 +772,20 @@ retry4:
 			return 0;
 #endif
 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
+#ifndef WIN32
 		if (SOCK_ERRNO == EWOULDBLOCK)
+#else
+		if (SOCK_ERRNO == WSAEWOULDBLOCK)
+#endif
 			return 0;
 #endif
 		/* We might get ECONNRESET here if using TCP and backend died */
 #ifdef ECONNRESET
+#ifndef WIN32
 		if (SOCK_ERRNO == ECONNRESET)
+#else
+		if (SOCK_ERRNO == WSAECONNRESET)
+#endif
 			goto definitelyFailed;
 #endif
 		/* pqsecure_read set the error message for us */
@@ -834,10 +858,18 @@ pqSendSome(PGconn *conn, int len)
 					break;
 #endif
 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
+#ifndef WIN32
 				case EWOULDBLOCK:
+#else
+				case WSAEWOULDBLOCK:
+#endif
 					break;
 #endif
+#ifndef WIN32
 				case EINTR:
+#else
+				case WSAEINTR:
+#endif
 					continue;
 
 				default:
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index b16968b..aa48bd8 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -451,12 +451,20 @@ rloop:
 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
 				case EWOULDBLOCK:
 #endif
+#ifndef WIN32
 				case EINTR:
+#else
+				case WSAEWOULDBLOCK:
+				case WSAEINTR:
+#endif
 					/* no error message, caller is expected to retry */
 					break;
 
 #ifdef ECONNRESET
 				case ECONNRESET:
+#ifdef WIN32
+				case WSAECONNRESET:
+#endif
 					printfPQExpBuffer(&conn->errorMessage,
 									  libpq_gettext(
 								"server closed the connection unexpectedly\n"
@@ -635,7 +643,12 @@ retry_masked:
 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
 				case EWOULDBLOCK:
 #endif
+#ifndef WIN32
 				case EINTR:
+#else
+				case WSAEWOULDBLOCK:
+				case WSAEINTR:
+#endif
 					/* no error message, caller is expected to retry */
 					break;
 
@@ -647,6 +660,9 @@ retry_masked:
 #ifdef ECONNRESET
 				case ECONNRESET:
 #endif
+#ifdef WIN32
+				case WSAECONNRESET:
+#endif
 					printfPQExpBuffer(&conn->errorMessage,
 									  libpq_gettext(
 								"server closed the connection unexpectedly\n"
-- 
1.8.3.1

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to