X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=libfcgi%2Fos_unix.c;h=cbd65d8033d0229d37d6b5c55e4ca592952d9fee;hb=af1b4cad97c093e021899eb02a1b4bb22a0c299d;hp=5f3105c4e23f47009dfe7756ad464473eb989af5;hpb=df986e9d4ccfd45bba9a32145f6a4727f4d9fde1;p=catagits%2Ffcgi2.git diff --git a/libfcgi/os_unix.c b/libfcgi/os_unix.c index 5f3105c..cbd65d8 100755 --- a/libfcgi/os_unix.c +++ b/libfcgi/os_unix.c @@ -17,7 +17,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: os_unix.c,v 1.34 2001/09/25 14:21:44 robs Exp $"; +static const char rcsid[] = "$Id: os_unix.c,v 1.38 2003/06/22 00:16:43 robs Exp $"; #endif /* not lint */ #include "fcgi_config.h" @@ -181,7 +181,7 @@ int OS_LibInit(int stdioFds[3]) FD_ZERO(&readFdSetPost); FD_ZERO(&writeFdSetPost); - OS_InstallSignalHandlers(FALSE); + OS_InstallSignalHandlers(TRUE); libInitialized = TRUE; @@ -285,7 +285,7 @@ union SockAddrUnion { int OS_CreateLocalIpcFd(const char *bindPath, int backlog) { int listenSock, servLen; - union SockAddrUnion sa; + union SockAddrUnion sa; int tcp = FALSE; unsigned long tcp_ia = 0; char *tp; @@ -638,7 +638,7 @@ int OS_AsyncRead(int fd, int offset, void *buf, int len, if(fd > maxFd) maxFd = fd; - if(index >= asyncIoTableSize) { + while (index >= asyncIoTableSize) { GrowAsyncTable(); } @@ -687,7 +687,7 @@ int OS_AsyncWrite(int fd, int offset, void *buf, int len, if(fd > maxFd) maxFd = fd; - if(index >= asyncIoTableSize) { + while (index >= asyncIoTableSize) { GrowAsyncTable(); } @@ -719,7 +719,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) { if (fd == -1) return 0; @@ -744,6 +744,37 @@ int OS_Close(int fd) maxFd--; } } + + /* + * shutdown() the send side and then read() from client until EOF + * or a timeout expires. This is done to minimize the potential + * that a TCP RST will be sent by our TCP stack in response to + * receipt of additional data from the client. The RST would + * cause the client to discard potentially useful response data. + */ + + if (shutdown_ok) + { + if (shutdown(fd, 1) == 0) + { + struct timeval tv; + fd_set rfds; + int rv; + char trash[1024]; + + FD_ZERO(&rfds); + + do + { + FD_SET(fd, &rfds); + tv.tv_sec = 2; + tv.tv_usec = 0; + rv = select(fd + 1, &rfds, NULL, NULL, &tv); + } + while (rv > 0 && read(fd, trash, sizeof(trash)) > 0); + } + } + return close(fd); } @@ -1201,9 +1232,9 @@ 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) { - return OS_Close(ipcFd); + return OS_Close(ipcFd, shutdown); } /*