IsFastCGI
skimo [Wed, 1 Nov 2000 15:12:24 +0000 (15:12 +0000)]
perl/ChangeLog
perl/FCGI.PL
perl/FCGI.pm

index 0cf6aab..417304d 100644 (file)
@@ -1,5 +1,6 @@
        o add example remote.fpl
        o provide access to the Request parameters
+       o add IsFastCGI method
 
 Version 0.55 --        18 October 2000   <skimo@kotnet.org> Sven Verdoolaege
 
index c6e61cb..fc436a8 100644 (file)
@@ -12,7 +12,7 @@ unless ($] >= 5.005) {
 print OUT while <DATA>;
 close OUT;
 __END__
-/* $Id: FCGI.PL,v 1.17 2000/11/01 14:27:49 skimo Exp $ */
+/* $Id: FCGI.PL,v 1.18 2000/11/01 15:12:26 skimo Exp $ */
 
 #include "EXTERN.h"
 #include "perl.h"
@@ -185,31 +185,38 @@ HV *hv;
     }
 }
 
-static int 
-FCGI_Accept(FCGP_Request* request)
+static int
+FCGI_IsFastCGI(FCGP_Request* request)
 {
     static int isCGI = -1; /* -1: not checked; 0: FCGI; 1: CGI */
 
-    int req_isCGI = 
-       request->requestPtr->listen_sock == FCGI_LISTENSOCK_FILENO ?
-       isCGI : 0;
+    if (request->requestPtr->listen_sock == FCGI_LISTENSOCK_FILENO) {
+       if (isCGI == -1)
+           isCGI = FCGX_IsCGI();
+       return !isCGI;
+    }
+
+    /* A explicit socket is being used -> assume FastCGI */
+    return 1;
+}
 
+static int 
+FCGI_Accept(FCGP_Request* request)
+{
     dTHX;
 
-    if(req_isCGI == -1) {
-        /*
-         * First call to FCGI_Accept.  Is application running
-         * as FastCGI or as CGI?
-         */
-        req_isCGI = isCGI = FCGX_IsCGI();
-    } else if(req_isCGI) {
+    if (!FCGI_IsFastCGI(request)) {
+       static int been_here = 0;
+
         /*
          * Not first call to FCGI_Accept and running as CGI means
          * application is done.
          */
-        return(EOF);
-    } 
-    if(!req_isCGI) {
+       if (been_here)
+           return EOF;
+
+       been_here = 1;
+    } else {
 #ifdef USE_SFIO
        int i;
 #endif
@@ -343,7 +350,7 @@ typedef FCGP_Request *      FCGI;
 typedef        GV*             GLOBREF;
 typedef        HV*             HASHREF;
 
-MODULE = FCGI          PACKAGE = FCGI
+MODULE = FCGI          PACKAGE = FCGI      PREFIX = FCGI_
 
 BOOT:
     FCGI_Init();
@@ -385,45 +392,24 @@ CloseSocket(socket)
     close(socket);
 
 int
-Accept(request)
+FCGI_Accept(request)
 
     FCGI    request;
 
     PROTOTYPE: $
 
-    CODE:
-    RETVAL = FCGI_Accept(request);
-
-    OUTPUT:
-    RETVAL
-
-
 void
-Finish(request)
-
+FCGI_Finish(request)
     FCGI    request;
 
     PROTOTYPE: $
 
-    CODE:
-    {
-        /*
-         * Finish the request.
-         */
-        FCGI_Finish(request);
-    }
-
-
 void
-Flush(request)
-
+FCGI_Flush(request)
     FCGI    request;
 
     PROTOTYPE: $
 
-    CODE:
-    FCGI_Flush(request);
-
 HV *
 GetEnvironment(request)
     FCGI    request;
@@ -448,7 +434,13 @@ GetHandles(request)
     PPCODE:
     EXTEND(sp,3);
     for (i = 0; i < 3; ++i)
-       PUSHs(sv_2mortal(newRV(request->gv[i])));
+       PUSHs(sv_2mortal(newRV((SV *) request->gv[i])));
+
+int
+FCGI_IsFastCGI(request)
+    FCGI    request;
+
+    PROTOTYPE: $
 
 void
 Detach(request)
@@ -474,18 +466,12 @@ Attach(request)
 
 
 int
-StartFilterData(request)
+FCGI_StartFilterData(request)
 
     FCGI    request;
 
     PROTOTYPE: $
 
-    CODE:
-    RETVAL = FCGI_StartFilterData(request);
-
-    OUTPUT:
-    RETVAL
-
 void
 DESTROY(request)
     FCGI    request;
index a22514f..7fa468c 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: FCGI.pm,v 1.13 2000/11/01 14:27:49 skimo Exp $
+# $Id: FCGI.pm,v 1.14 2000/11/01 15:12:27 skimo Exp $
 
 package FCGI;
 
@@ -239,6 +239,10 @@ Returns the environment parameter passed to FCGI::Request.
 
 Returns the file handle parameters passed to FCGI::Request.
 
+=item $isfcgi = $req->IsFastCGI()
+
+Returns whether or not the program was run as a FastCGI.
+
 =back
 
 =head1 AUTHOR