1 # $Id: FCGI.pm,v 1.9 2000/04/21 18:10:53 skimo Exp $
8 @ISA = qw(Exporter DynaLoader);
9 # Items to export into callers namespace by default. Note: do not export
10 # names by default without a very good reason. Use EXPORT_OK instead.
11 # Do not simply export all your public functions/methods/constants.
20 # Preloaded methods go here.
22 # Autoload methods go after __END__, and are processed by the autosplit program.
24 *FAIL_ACCEPT_ON_INTR = sub() { 1 };
26 sub Request(;***$$$) {
27 my @defaults = (\*STDIN, \*STDOUT, \*STDERR, \%ENV, 0, 0);
28 splice @defaults,0,@_,@_;
33 if (defined %FCGI::ENV) {
38 my $rc = Accept($global_request);
39 for (keys %FCGI::ENV) {
40 $ENV{$_} = $FCGI::ENV{$_} unless exists $ENV{$_};
44 $SIG{__WARN__} = $SIG{__DIE__} = $warn_die_handler if (tied (*STDIN));
50 %ENV = %FCGI::ENV if (defined %FCGI::ENV);
54 for (qw(__WARN__ __DIE__)) {
55 delete $SIG{$_} if ($SIG{$_} == $warn_die_handler);
59 Finish ($global_request);
63 Flush($global_request);
67 Detach($global_request);
71 Attach($global_request);
78 sub start_filter_data() {
79 StartFilterData($global_request);
82 $global_request = Request();
83 $warn_die_handler = sub { print STDERR @_ unless $^S };
88 shift->PRINT(sprintf(shift, @_));
97 FCGI - Fast CGI module
104 my $request = FCGI::Request();
106 while($request->accept() >= 0) {
107 print("Content-type: text/html\r\n\r\n", ++$count);
118 Creates a request handle. It has the following optional parameters:
122 =item input perl file handle (default: \*STDIN)
124 =item output perl file handle (default: \*STDOUT)
126 =item error perl file handle (default: \*STDERR)
128 These filehandles will be setup to act as input/output/error
131 =item environment hash reference (default: \%ENV)
133 The hash will be populated with the environment.
135 =item socket (default: 0)
137 Socket to communicate with the server.
138 Can be the result of the OpenSocket function.
139 For the moment, it's the file descriptor of the socket
140 that should be passed. This may change in the future.
142 =item flags (default: 0)
148 =item FCGI::FAIL_ACCEPT_ON_INTR
150 If set, Accept will fail if interrupted.
151 It not set, it will just keep on waiting.
158 my $req = FCGI::Request;
162 my $in = new IO::Handle;
163 my $out = new IO::Handle;
164 my $err = new IO::Handle;
165 my $req = FCGI::Request($in, $out, $err, \%env);
167 =item FCGI::OpenSocket(path, backlog)
169 =item FCGI::CloseSocket(socket)
171 Close a socket opened with OpenSocket.
175 Accepts a connection on $req, attaching the filehandles and
176 populating the environment hash.
177 Returns 0 on success.
178 If a connection has been accepted before, the old
179 one will be finished first.
181 Note that unlike with the old interface, no die and warn
182 handlers are installed by default.
186 Finishes accepted connection.
187 Also detaches filehandles.
191 Flushes accepted connection.
195 Temporarily detaches filehandles on an accepted connection.
199 Re-attaches filehandles on an accepted connection.
205 Sven Verdoolaege <skimo@kotnet.org>