summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/port/win32/socket.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c
index b75067d9ca..5ec9cc29cb 100644
--- a/src/backend/port/win32/socket.c
+++ b/src/backend/port/win32/socket.c
@@ -322,12 +322,10 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f)
wbuf.buf = buf;
r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL);
- if (r != SOCKET_ERROR && b > 0)
- /* Read succeeded right away */
- return b;
+ if (r != SOCKET_ERROR)
+ return b; /* success */
- if (r == SOCKET_ERROR &&
- WSAGetLastError() != WSAEWOULDBLOCK)
+ if (WSAGetLastError() != WSAEWOULDBLOCK)
{
TranslateSocketError();
return -1;
@@ -343,7 +341,7 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f)
return -1;
}
- /* No error, zero bytes (win2000+) or error+WSAEWOULDBLOCK (<=nt4) */
+ /* We're in blocking mode, so wait for data */
for (n = 0; n < 5; n++)
{
@@ -352,25 +350,22 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f)
return -1; /* errno already set */
r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL);
- if (r == SOCKET_ERROR)
+ if (r != SOCKET_ERROR)
+ return b; /* success */
+ if (WSAGetLastError() != WSAEWOULDBLOCK)
{
- if (WSAGetLastError() == WSAEWOULDBLOCK)
- {
- /*
- * There seem to be cases on win2k (at least) where WSARecv
- * can return WSAEWOULDBLOCK even when
- * pgwin32_waitforsinglesocket claims the socket is readable.
- * In this case, just sleep for a moment and try again. We try
- * up to 5 times - if it fails more than that it's not likely
- * to ever come back.
- */
- pg_usleep(10000);
- continue;
- }
TranslateSocketError();
return -1;
}
- return b;
+
+ /*
+ * There seem to be cases on win2k (at least) where WSARecv can return
+ * WSAEWOULDBLOCK even when pgwin32_waitforsinglesocket claims the
+ * socket is readable. In this case, just sleep for a moment and try
+ * again. We try up to 5 times - if it fails more than that it's not
+ * likely to ever come back.
+ */
+ pg_usleep(10000);
}
ereport(NOTICE,
(errmsg_internal("could not read from ready socket (after retries)")));