add attach()/detach() support
[catagits/fcgi2.git] / libfcgi / os_win32.c
index 294b17f..a0309b8 100755 (executable)
@@ -17,7 +17,7 @@
  *  significantly more enjoyable.)
  */
 #ifndef lint
-static const char rcsid[] = "$Id: os_win32.c,v 1.33 2002/03/05 18:15:15 robs Exp $";
+static const char rcsid[] = "$Id: os_win32.c,v 1.34 2003/06/22 00:16:43 robs Exp $";
 #endif /* not lint */
 
 #define WIN32_LEAN_AND_MEAN 
@@ -1352,7 +1352,7 @@ int OS_AsyncWrite(int fd, int offset, void *buf, int len,
  *
  *--------------------------------------------------------------
  */
-int OS_Close(int fd)
+int OS_Close(int fd, int shutdown_ok)
 {
     int ret = 0;
 
@@ -1381,24 +1381,30 @@ int OS_Close(int fd)
          * cause the client to discard potentially useful response data.
          */
 
-        if (shutdown(fdTable[fd].fid.sock, SD_SEND) == 0)
+        if (shutdown_ok)
         {
-            struct timeval tv;
-            fd_set rfds;
-            int sock = fdTable[fd].fid.sock;
-            int rv;
-            char trash[1024];
+            if (shutdown(fdTable[fd].fid.sock, SD_SEND) == 0)
+            {
+                struct timeval tv;
+                fd_set rfds;
+                int sock = fdTable[fd].fid.sock;
+                int rv;
+                char trash[1024];
    
-            FD_ZERO(&rfds);
+                FD_ZERO(&rfds);
 
-            do 
-            {
-                   FD_SET(sock, &rfds);
+                do 
+                {
+#pragma warning( disable : 4127 ) 
+                   FD_SET((unsigned) sock, &rfds);
+#pragma warning( default : 4127 )
+                    
                    tv.tv_sec = 2;
                    tv.tv_usec = 0;
                    rv = select(sock + 1, &rfds, NULL, NULL, &tv);
+                }
+                while (rv > 0 && recv(sock, trash, sizeof(trash), 0) > 0);
             }
-            while (rv > 0 && recv(sock, trash, sizeof(trash), 0) > 0);
         }
         
         closesocket(fdTable[fd].fid.sock);
@@ -1791,7 +1797,7 @@ int OS_Accept(int listen_sock, int fail_on_intr, const char *webServerAddrs)
  *
  *----------------------------------------------------------------------
  */
-int OS_IpcClose(int ipcFd)
+int OS_IpcClose(int ipcFd, int shutdown)
 {
     if (ipcFd == -1) return 0;
 
@@ -1816,7 +1822,7 @@ int OS_IpcClose(int ipcFd)
 
     case FD_SOCKET_SYNC:
 
-           OS_Close(ipcFd);
+           OS_Close(ipcFd, shutdown);
            break;
 
     case FD_UNUSED: