print OUT while <DATA>;
close OUT;
__END__
-/* $Id: FCGI.PL,v 1.10 1999/08/03 15:52:53 skimo Exp $ */
+/* $Id: FCGI.PL,v 1.11 1999/08/10 11:06:37 skimo Exp $ */
#include "EXTERN.h"
#include "perl.h"
SV* svout;
SV* sverr;
GV* gv[3];
- GV* gvNew[3];
HV* hvEnv;
- FCGX_Stream* in;
FCGX_Request* requestPtr;
#ifdef USE_SFIO
int sfcreated[3];
sv_unmagic((SV *)request->gv[1], 'q');
sv_unmagic((SV *)request->gv[2], 'q');
#endif
- request->in = NULL;
FCGX_Finish_r(request->requestPtr);
request->bound = FALSE;
}
SV *sv;
dTHX;
+ hv_clear(hv);
for(i = 0; ; i++) {
if((p = envp[i]) == NULL) {
break;
IO *io[3];
int i;
#endif
- FCGX_Stream *out, *error;
- FCGX_ParamArray envp;
+ FCGX_Request *fcgx_req = request->requestPtr;
int acceptResult;
if(request->bound) {
#if defined(USE_LOCKING) && defined(USE_THREADS)
MUTEX_LOCK(&accept_mutex);
#endif
- acceptResult = FCGX_Accept_r(&request->in, &out, &error,
- &envp, request->requestPtr);
+ acceptResult = FCGX_Accept_r(fcgx_req);
#if defined(USE_LOCKING) && defined(USE_THREADS)
MUTEX_UNLOCK(&accept_mutex);
#endif
return acceptResult;
}
- populate_env(envp, request->hvEnv);
+ populate_env(fcgx_req->envp, request->hvEnv);
#ifdef USE_SFIO
for (i = 0; i < 3; ++i) {
- io[i] = GvIOn(request->gv[i] = request->gvNew[i]);
+ io[i] = GvIOn(request->gv[i]);
if (!(i == 0 ? IoIFP(io[i]) : IoOFP(io[i]))) {
IoIFP(io[i]) = sftmp(0);
/*IoIFP(io[i]) = sfnew(NULL, NULL, SF_UNBOUND, 0,
request->sfcreated[i] = TRUE;
}
}
- sfdisc(IoIFP(io[0]), sfdcnewfcgi(request->in));
- sfdisc(IoOFP(io[1]), sfdcnewfcgi(out));
- sfdisc(IoOFP(io[2]), sfdcnewfcgi(error));
+ sfdisc(IoIFP(io[0]), sfdcnewfcgi(fcgx_req->in));
+ sfdisc(IoOFP(io[1]), sfdcnewfcgi(fcgx_req->out));
+ sfdisc(IoOFP(io[2]), sfdcnewfcgi(fcgx_req->err));
#else
if (!request->svout) {
newSVrv(request->svout = newSV(0), "FCGI::Stream");
newSVrv(request->sverr = newSV(0), "FCGI::Stream");
newSVrv(request->svin = newSV(0), "FCGI::Stream");
}
- sv_magic((SV *)request->gv[1] = request->gvNew[1],
- request->svout, 'q', Nullch, 0);
- sv_magic((SV *)request->gv[2] = request->gvNew[2],
- request->sverr, 'q', Nullch, 0);
- sv_magic((SV *)request->gv[0] = request->gvNew[0],
- request->svin, 'q', Nullch, 0);
- sv_setiv(SvRV(request->svout), (IV) out);
- sv_setiv(SvRV(request->sverr), (IV) error);
- sv_setiv(SvRV(request->svin), (IV) request->in);
+ sv_magic((SV *)request->gv[1], request->svout, 'q', Nullch, 0);
+ sv_magic((SV *)request->gv[2], request->sverr, 'q', Nullch, 0);
+ sv_magic((SV *)request->gv[0], request->svin, 'q', Nullch, 0);
+ sv_setiv(SvRV(request->svout), (IV) fcgx_req->out);
+ sv_setiv(SvRV(request->sverr), (IV) fcgx_req->err);
+ sv_setiv(SvRV(request->svin), (IV) fcgx_req->in);
#endif
request->bound = TRUE;
}
static int
FCGI_StartFilterData(FCGP_Request* request)
{
- return request->in ? FCGX_StartFilterData(request->in) : -1;
-}
-
-static void
-FCGI_SetExitStatus(FCGP_Request* request, int status)
-{
- if (request->in) FCGX_SetExitStatus(status, request->in);
+ return request->requestPtr->in ?
+ FCGX_StartFilterData(request->requestPtr->in) : -1;
}
static FCGP_Request *
-FCGI_Request()
+FCGI_Request(in, out, err, env, socket, flags)
+ GV* in;
+ GV* out;
+ GV* err;
+ HV* env;
+ int socket;
+ int flags;
{
FCGX_Request* fcgx_req;
FCGP_Request* req;
Newz(551, fcgx_req, 1, FCGX_Request);
+ FCGX_InitRequest(fcgx_req, socket, flags);
Newz(551, req, 1, FCGP_Request);
req->requestPtr = fcgx_req;
+ req->gv[0] = in;
+ req->gv[1] = out;
+ req->gv[2] = err;
+ req->hvEnv = env;
return req;
}
static void
FCGI_Release_Request(FCGP_Request *req)
{
+ FCGI_Finish(req);
Safefree(req->requestPtr);
Safefree(req);
}
FCGI_Init();
SV *
-Request()
+RequestX(in, out, err, env, socket, flags)
+ GLOBREF in;
+ GLOBREF out;
+ GLOBREF err;
+ HASHREF env;
+ int socket;
+ int flags;
- PROTOTYPE:
+ PROTOTYPE: ***$$$
CODE:
- RETVAL = sv_setref_pv(newSV(0), "FCGI", FCGI_Request());
+ RETVAL = sv_setref_pv(newSV(0), "FCGI",
+ FCGI_Request(in, out, err, env, socket, flags));
OUTPUT:
RETVAL
int
-Accept(request, in, out, err, env)
+Accept(request)
FCGI request;
- GLOBREF in;
- GLOBREF out;
- GLOBREF err;
- HASHREF env;
- PROTOTYPE: $***$
+ PROTOTYPE: $
CODE:
- request->gvNew[0] = in;
- request->gvNew[1] = out;
- request->gvNew[2] = err;
- request->hvEnv = env;
-
RETVAL = FCGI_Accept(request);
OUTPUT:
-# $Id: FCGI.pm,v 1.4 1999/08/03 15:52:54 skimo Exp $
+# $Id: FCGI.pm,v 1.5 1999/08/10 11:06:37 skimo Exp $
package FCGI;
# Autoload methods go after __END__, and are processed by the autosplit program.
-sub request() {
- Request();
+sub Request(;***$$$) {
+ my @defaults = (\*STDIN, \*STDOUT, \*STDERR, \%ENV, 0, 0);
+ splice @defaults,0,@_,@_;
+ RequestX(@defaults);
}
-sub accept(;$***$) {
- return Accept(@_) if @_ == 5;
-
+sub accept() {
if (defined %FCGI::ENV) {
%ENV = %FCGI::ENV;
} else {
%FCGI::ENV = %ENV;
}
- my $rc = Accept($global_request, \*STDIN, \*STDOUT, \*STDERR, \%ENV);
+ my $rc = Accept($global_request);
+ for (keys %FCGI::ENV) {
+ $ENV{$_} = $FCGI::ENV{$_} unless exists $ENV{$_};
+ }
# not SFIO
$SIG{__WARN__} = $SIG{__DIE__} = $warn_die_handler if (tied (*STDIN));
return $rc;
}
-sub finish(;$) {
- return Finish(@_) if @_ == 1;
-
+sub finish() {
%ENV = %FCGI::ENV if (defined %FCGI::ENV);
# not SFIO
Finish ($global_request);
}
-sub flush(;$) {
- return Flush(@_) if @_ == 1;
-
+sub flush() {
Flush($global_request);
}
sub set_exit_status {
}
-sub start_filter_data(;$) {
- return StartFilterData(@_) if @_ == 1;
-
+sub start_filter_data() {
StartFilterData($global_request);
}
my $out = new IO::Handle;
my $err = new IO::Handle;
- my $request = FCGI::Request();
+ my $request = FCGI::Request($in, $out, $err, \%env);
- while ($request->Accept($in, $out, $err, \%env) >= 0) {
+ while ($request->Accept() >= 0) {
print $out
"Content-type: text/html\r\n",
"\r\n",
- "<title>FastCGI Hello! (multi-threaded C, fcgiapp library)</title>",
- "<h1>FastCGI Hello! (multi-threaded C, fcgiapp library)</h1>",
+ "<title>FastCGI Hello! (multi-threaded perl, fcgiapp library)</title>",
+ "<h1>FastCGI Hello! (multi-threaded perl, fcgiapp library)</h1>",
"Request counts for ", THREAD_COUNT ," threads ",
"running on host <i>$env{SERVER_NAME}</i><P><CODE>";