no message
[catagits/fcgi2.git] / perl / FCGI.PL
index be2b204..8133f35 100644 (file)
@@ -1,4 +1,5 @@
 use Config;
+use ExtUtils::MakeMaker;
 
 do 'FCGI.cfg' or die "no FCGI.cfg";
 
@@ -6,7 +7,7 @@ open OUT, ">FCGI.pm";
 
 print "Generating FCGI.pm\n";
 print OUT <<'EOP';
-# $Id: FCGI.PL,v 1.22 2000/12/31 21:56:10 skimo Exp $
+# $Id: FCGI.PL,v 1.34 2001/10/04 08:04:16 skimo Exp $
 
 package FCGI;
 
@@ -21,10 +22,10 @@ require DynaLoader;
        
 );
 
-$VERSION = '0.59';
-
 EOP
 
+print OUT '$VERSION = '.MM->parse_version('version.pm').";\n\n";
+
 print OUT "bootstrap FCGI;\n" unless ($pure);
 
 print OUT <<'EOP' if ($pure);
@@ -47,6 +48,9 @@ use constant FILTER => 3;
                      AUTHORIZER, "AUTHORIZER",
                      FILTER, "FILTER",
                     );
+
+# This only works on Unix; anyone familiar with Windows is welcome
+# to give a hand here
 sub IsFastCGI {
     my ($req) = @_;
     $req->{isfastcgi} =
@@ -55,12 +59,17 @@ sub IsFastCGI {
     return $req->{isfastcgi};
 }
 
+sub GetEnvironment {
+    return shift->{'env'};
+}
+
 sub read_nv_len {
     my ($stream) = @_;
     my $buf;
     return undef unless read $stream, $buf, 1, 0;
     my ($len) = unpack("C", $buf);
     if ($len & 0x80) {
+       $buf = pack("C", $len & 0x7F);
        return undef unless read $stream, $buf, 3, 1;
        $len = unpack("N", $buf);
     }
@@ -75,6 +84,7 @@ sub RequestX {
        env => shift,
        socket => shift,
        flags => shift,
+       last => 0,
     };
     open $self->{listen_sock}, "<&=0";
     bless $self, "FCGI";
@@ -93,7 +103,7 @@ sub Accept {
     }
     $req->Finish();
     $req->{socket} = gensym();
-    if (!accept($req->{socket}, $req->{listen_sock})) {
+    if ($req->{last} || !accept($req->{socket}, $req->{listen_sock})) {
        $req->{error} = "accept";
        return -1;
     }
@@ -161,6 +171,10 @@ sub Finish {
     $req->{accepted} = 0;
 }
 
+sub LastCall {
+    shift->{last} = 1;
+}
+
 sub DESTROY {
     shift->Finish();
 }
@@ -260,8 +274,9 @@ __END__
 
 *FAIL_ACCEPT_ON_INTR = sub() { 1 };
 
-sub Request(;***$$$) {
+sub Request(;***$*$) {
     my @defaults = (\*STDIN, \*STDOUT, \*STDERR, \%ENV, 0, 0);
+    $_[4] = fileno($_[4]) if defined($_[4]) && defined(fileno($_[4]));
     splice @defaults,0,@_,@_;
     RequestX(@defaults);
 }
@@ -331,6 +346,9 @@ sub PRINTF {
   shift->PRINT(sprintf(shift, @_));
 }
 
+sub BINMODE {
+}
+
 sub READLINE {
     my $stream = shift;
     my ($s, $c);
@@ -415,6 +433,14 @@ Can be the result of the OpenSocket function.
 For the moment, it's the file descriptor of the socket
 that should be passed. This may change in the future.
 
+You should only use your own socket if your program
+is not started by a process manager such as mod_fastcgi
+(except for the FastCgiExternalServer case) or cgi-fcgi. 
+If you use the option, you have to let your FastCGI
+server know which port (and possibly server) your program
+is listening on.
+See remote.pl for an example.
+
 =item flags (default: 0)
 
 Possible values:
@@ -449,6 +475,11 @@ Creates a socket suitable to use as an argument to Request.
 =item path
 
 Pathname of socket or colon followed by local tcp port.
+Note that some systems take file permissions into account
+on Unix domain sockets, so you'll have to make sure that
+the server can write to the created file, by changing
+the umask before the call and/or changing permissions and/or
+group of the file afterwards.
 
 =item backlog
 
@@ -495,6 +526,14 @@ Temporarily detaches filehandles on an accepted connection.
 
 Re-attaches filehandles on an accepted connection.
 
+=item $req->LastCall()
+
+Tells the library not to accept any more requests on this handle.
+It should be safe to call this method from signal handlers.
+
+Note that this method is still experimental and everything
+about it, including its name, is subject to change.
+
 =item $env = $req->GetEnvironment()
 
 Returns the environment parameter passed to FCGI::Request.