X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=libfcgi%2Ffcgiapp.c;h=2613031aae07fc7e69f7ae3a987233fd81464e0f;hb=c4d74207308dfafa652925306c6b2828843e0e97;hp=2879300f81a44726cc88f971ff1919ffa8df081a;hpb=796f8a6080afd9eab4c469b016c6382b59192872;p=catagits%2Ffcgi2.git diff --git a/libfcgi/fcgiapp.c b/libfcgi/fcgiapp.c index 2879300..2613031 100644 --- a/libfcgi/fcgiapp.c +++ b/libfcgi/fcgiapp.c @@ -11,7 +11,7 @@ * */ #ifndef lint -static const char rcsid[] = "$Id: fcgiapp.c,v 1.28 2001/08/30 22:27:51 robs Exp $"; +static const char rcsid[] = "$Id: fcgiapp.c,v 1.35 2003/06/22 00:16:43 robs Exp $"; #endif /* not lint */ #include @@ -71,6 +71,11 @@ static int isFastCGI = -1; static char *webServerAddressList = NULL; static FCGX_Request the_request; +void FCGX_ShutdownPending(void) +{ + OS_ShutdownPending(); +} + static void *Malloc(size_t size) { void *result = malloc(size); @@ -102,14 +107,20 @@ static char *StringCopy(char *str) */ int FCGX_GetChar(FCGX_Stream *stream) { - if(stream->rdNext != stream->stop) - return *stream->rdNext++; - if(stream->isClosed || !stream->isReader) + if (stream->isClosed || ! stream->isReader) return EOF; + + if (stream->rdNext != stream->stop) + return *stream->rdNext++; + stream->fillBuffProc(stream); + if (stream->isClosed) + return EOF; + stream->stopUnget = stream->rdNext; - if(stream->rdNext != stream->stop) + if (stream->rdNext != stream->stop) return *stream->rdNext++; + ASSERT(stream->isClosed); /* bug in fillBufProc if not */ return EOF; } @@ -133,7 +144,7 @@ int FCGX_GetStr(char *str, int n, FCGX_Stream *stream) { int m, bytesMoved; - if(n <= 0) { + if (stream->isClosed || ! stream->isReader || n <= 0) { return 0; } /* @@ -158,10 +169,13 @@ int FCGX_GetStr(char *str, int n, FCGX_Stream *stream) if(bytesMoved == n) return bytesMoved; str += m; - } + } if(stream->isClosed || !stream->isReader) return bytesMoved; stream->fillBuffProc(stream); + if (stream->isClosed) + return bytesMoved; + stream->stopUnget = stream->rdNext; } } @@ -932,8 +946,9 @@ static void SetError(FCGX_Stream *stream, int FCGI_errno) */ if(stream->FCGI_errno == 0) { stream->FCGI_errno = FCGI_errno; - stream->isClosed = TRUE; } + + stream->isClosed = TRUE; } /* @@ -1998,8 +2013,19 @@ void FCGX_Finish_r(FCGX_Request *reqDataPtr) if (reqDataPtr->in) { close |= FCGX_FClose(reqDataPtr->err); close |= FCGX_FClose(reqDataPtr->out); + close |= FCGX_GetError(reqDataPtr->in); - close |= FCGX_GetError(reqDataPtr->in); + /* discard any remaining data in input stream */ + if (!close && !reqDataPtr->in->isClosed) { + FCGX_Stream *stream = reqDataPtr->in; + + do { + stream->rdNext = stream->stop; + stream->fillBuffProc(stream); + } while (!stream->isClosed); + + close |= FCGX_GetError(stream); + } } FCGX_Free(reqDataPtr, close); @@ -2016,8 +2042,9 @@ void FCGX_Free(FCGX_Request * request, int close) FreeParams(&request->paramsPtr); if (close) { - OS_IpcClose(request->ipcFd); + OS_IpcClose(request->ipcFd, ! request->detached); request->ipcFd = -1; + request->detached = 0; } } @@ -2292,3 +2319,23 @@ void FCGX_SetExitStatus(int status, FCGX_Stream *stream) data->reqDataPtr->appStatus = status; } + +int +FCGX_Attach(FCGX_Request * r) +{ + r->detached = FALSE; + return 0; +} + + +int +FCGX_Detach(FCGX_Request * r) +{ + if (r->ipcFd <= 0) + { + return -1; + } + + r->detached = TRUE; + return 0; +}