summaryrefslogtreecommitdiff
path: root/src/backend/port/win32/socket.c
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2010-02-16 19:26:02 +0000
committerMagnus Hagander <magnus@hagander.net>2010-02-16 19:26:02 +0000
commit215cbc90f8db3fc8a70af5572b156f49216c2f70 (patch)
tree23cae32cf9e7b6d38bc55e876f2ba2be115cf5c9 /src/backend/port/win32/socket.c
parent492eaefb90b9e60b608a1a4b2e3e68ce7c6c7c69 (diff)
downloadpostgresql-215cbc90f8db3fc8a70af5572b156f49216c2f70.tar.gz
Add emulation of non-blocking sockets to the win32 socket/signal layer,
and use this in pq_getbyte_if_available. It's only a limited implementation which swithes the whole emulation layer no non-blocking mode, but that's enough as long as non-blocking is only used during a short period of time, and only one socket is accessed during this time.
Diffstat (limited to 'src/backend/port/win32/socket.c')
-rw-r--r--src/backend/port/win32/socket.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c
index 8076b8caef..af42576cab 100644
--- a/src/backend/port/win32/socket.c
+++ b/src/backend/port/win32/socket.c
@@ -6,13 +6,26 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.23 2010/01/02 16:57:50 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.24 2010/02/16 19:26:02 mha Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
+/*
+ * Indicate if pgwin32_recv() should operate in non-blocking mode.
+ *
+ * Since the socket emulation layer always sets the actual socket to
+ * non-blocking mode in order to be able to deliver signals, we must
+ * specify this in a separate flag if we actually need non-blocking
+ * operation.
+ *
+ * This flag changes the behaviour *globally* for all socket operations,
+ * so it should only be set for very short periods of time.
+ */
+int pgwin32_noblock = 0;
+
#undef socket
#undef accept
#undef connect
@@ -310,6 +323,16 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f)
return -1;
}
+ if (pgwin32_noblock)
+ {
+ /*
+ * No data received, and we are in "emulated non-blocking mode", so return
+ * indicating thta we'd block if we were to continue.
+ */
+ errno = EWOULDBLOCK;
+ return -1;
+ }
+
/* No error, zero bytes (win2000+) or error+WSAEWOULDBLOCK (<=nt4) */
for (n = 0; n < 5; n++)