*** a/src/backend/libpq/pqcomm.c
--- b/src/backend/libpq/pqcomm.c
***************
*** 837,845 **** pq_getbyte_if_available(unsigned char *c)
--- 837,849 ----
  	}
  
  	/* Temporarily put the socket into non-blocking mode */
+ #ifdef WIN32
+ 	pgwin32_noblock = 1;
+ #else
  	if (!pg_set_noblock(MyProcPort->sock))
  		ereport(ERROR,
  				(errmsg("couldn't put socket to non-blocking mode: %m")));
+ #endif
  	MyProcPort->noblock = true;
  	PG_TRY();
  	{
***************
*** 851,866 **** pq_getbyte_if_available(unsigned char *c)
--- 855,878 ----
  		 * The rest of the backend code assumes the socket is in blocking
  		 * mode, so treat failure as FATAL.
  		 */
+ #ifdef WIN32
+ 		pgwin32_noblock = 0;
+ #else
  		if (!pg_set_block(MyProcPort->sock))
  			ereport(FATAL,
  					(errmsg("couldn't put socket to blocking mode: %m")));
+ #endif
  		MyProcPort->noblock = false;
  		PG_RE_THROW();
  	}
  	PG_END_TRY();
+ #ifdef WIN32
+ 	pgwin32_noblock = 0;
+ #else
  	if (!pg_set_block(MyProcPort->sock))
  		ereport(FATAL,
  				(errmsg("couldn't put socket to blocking mode: %m")));
+ #endif
  	MyProcPort->noblock = false;
  
  	return r;
*** a/src/backend/port/win32/socket.c
--- b/src/backend/port/win32/socket.c
***************
*** 13,18 ****
--- 13,26 ----
  
  #include "postgres.h"
  
+ /*
+  * This indicates whether pgwin32_recv() is blocked until the receive
+  * operation has been finished. A value of zero blocks it even if
+  * the socket is set to non-blocking mode. A non-zero value makes it
+  * return immediately whether data is available or not.
+  */
+ int	pgwin32_noblock = 0;
+ 
  #undef socket
  #undef accept
  #undef connect
***************
*** 315,321 **** pgwin32_recv(SOCKET s, char *buf, int len, int f)
  	for (n = 0; n < 5; n++)
  	{
  		if (pgwin32_waitforsinglesocket(s, FD_READ | FD_CLOSE | FD_ACCEPT,
! 										INFINITE) == 0)
  			return -1;			/* errno already set */
  
  		r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL);
--- 323,330 ----
  	for (n = 0; n < 5; n++)
  	{
  		if (pgwin32_waitforsinglesocket(s, FD_READ | FD_CLOSE | FD_ACCEPT,
! 										(pgwin32_noblock == 0) ? INFINITE : 0)
! 			== 0)
  			return -1;			/* errno already set */
  
  		r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL);
*** a/src/include/port/win32.h
--- b/src/include/port/win32.h
***************
*** 283,288 **** int			pgwin32_send(SOCKET s, char *buf, int len, int flags);
--- 283,290 ----
  const char *pgwin32_socket_strerror(int err);
  int			pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
  
+ extern int	pgwin32_noblock;
+ 
  /* in backend/port/win32/security.c */
  extern int	pgwin32_is_admin(void);
  extern int	pgwin32_is_service(void);