prevent multiplexing Windows kernel event objects we listen for across various socket...
authorAndrew Dunstan <andrew@dunslane.net>
Sat, 29 Jul 2006 20:14:40 +0000 (20:14 +0000)
committerAndrew Dunstan <andrew@dunslane.net>
Sat, 29 Jul 2006 20:14:40 +0000 (20:14 +0000)
src/backend/port/win32/socket.c

index e65197e4d96f8d14fb062d43dc21712b361d348b..5ff2e3651cfa1d25618c48e581f54656fb1352cc 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.8 2004/12/31 22:00:37 pgsql Exp $
+ *   $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.8.4.1 2006/07/29 20:14:40 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -106,6 +106,7 @@ int
 pgwin32_waitforsinglesocket(SOCKET s, int what)
 {
    static HANDLE waitevent = INVALID_HANDLE_VALUE;
+   static SOCKET current_socket = -1;
    HANDLE      events[2];
    int         r;
 
@@ -121,6 +122,15 @@ pgwin32_waitforsinglesocket(SOCKET s, int what)
        ereport(ERROR,
                (errmsg_internal("Failed to reset socket waiting event: %i", (int) GetLastError())));
 
+   /*
+    * make sure we don't multiplex this with a different socket 
+    * from a previous call
+    */
+
+   if (current_socket != s && current_socket != -1)
+       WSAEventSelect(current_socket, waitevent, 0);
+
+   current_socket = s;
 
    if (WSAEventSelect(s, waitevent, what) == SOCKET_ERROR)
    {