#define INT2PTR(a,b) ((a) (b))
#endif
-#ifdef USE_SFIO
-typedef struct
-{
- Sfdisc_t disc;
- FCGX_Stream *stream;
-} FCGI_Disc;
-
-static ssize_t
-sffcgiread(f, buf, n, disc)
-Sfio_t* f; /* stream involved */
-Void_t* buf; /* buffer to read into */
-size_t n; /* number of bytes to read */
-Sfdisc_t* disc; /* discipline */
-{
- return FCGX_GetStr(buf, n, ((FCGI_Disc *)disc)->stream);
-}
-
-static ssize_t
-sffcgiwrite(f, buf, n, disc)
-Sfio_t* f; /* stream involved */
-const Void_t* buf; /* buffer to read into */
-size_t n; /* number of bytes to read */
-Sfdisc_t* disc; /* discipline */
-{
- n = FCGX_PutStr(buf, n, ((FCGI_Disc *)disc)->stream);
- FCGX_FFlush(((FCGI_Disc *)disc)->stream);
- return n;
-}
-
-Sfdisc_t *
-sfdcnewfcgi(stream)
- FCGX_Stream *stream;
-{
- FCGI_Disc* disc;
-
- New(1000,disc,1,FCGI_Disc);
- if (!disc) return (Sfdisc_t *)disc;
-
- disc->disc.exceptf = (Sfexcept_f)NULL;
- disc->disc.seekf = (Sfseek_f)NULL;
- disc->disc.readf = sffcgiread;
- disc->disc.writef = sffcgiwrite;
- disc->stream = stream;
- return (Sfdisc_t *)disc;
-}
-
-Sfdisc_t *
-sfdcdelfcgi(disc)
- Sfdisc_t* disc;
-{
- Safefree(disc);
- return 0;
-}
-#endif
-
#if defined(USE_LOCKING) && defined(USE_THREADS)
static perl_mutex accept_mutex;
#endif
GV* gv[3];
HV* hvEnv;
FCGX_Request* requestPtr;
-#ifdef USE_SFIO
- int sfcreated[3];
- IO* io[3];
-#endif
} FCGP_Request;
static void FCGI_Finish(FCGP_Request* request);
dTHX;
if(!request->bound)
return;
-#ifdef USE_SFIO
- sfsync(IoOFP(GvIOp(request->gv[1])));
- sfsync(IoOFP(GvIOp(request->gv[2])));
-#else
FCGX_FFlush(INT2PTR(FCGX_Stream *, SvIV((SV*) SvRV(request->svout))));
FCGX_FFlush(INT2PTR(FCGX_Stream *, SvIV((SV*) SvRV(request->sverr))));
-#endif
}
static void
FCGI_UndoBinding(FCGP_Request* request) {
dTHX;
-#ifdef USE_SFIO
- sfdcdelfcgi(sfdisc(IoIFP(request->io[0]), SF_POPDISC));
- sfdcdelfcgi(sfdisc(IoOFP(request->io[1]), SF_POPDISC));
- sfdcdelfcgi(sfdisc(IoOFP(request->io[2]), SF_POPDISC));
-#else
-# ifdef USE_PERLIO
+#ifdef USE_PERLIO
sv_unmagic((SV *)GvIOp(request->gv[0]), 'q');
sv_unmagic((SV *)GvIOp(request->gv[1]), 'q');
sv_unmagic((SV *)GvIOp(request->gv[2]), 'q');
-# else
+#else
sv_unmagic((SV *)request->gv[0], 'q');
sv_unmagic((SV *)request->gv[1], 'q');
sv_unmagic((SV *)request->gv[2], 'q');
-# endif
#endif
request->bound = FALSE;
}
static void
FCGI_Bind(FCGP_Request* request) {
dTHX;
-#ifdef USE_SFIO
- sfdisc(IoIFP(request->io[0]), sfdcnewfcgi(request->requestPtr->in));
- sfdisc(IoOFP(request->io[1]), sfdcnewfcgi(request->requestPtr->out));
- sfdisc(IoOFP(request->io[2]), sfdcnewfcgi(request->requestPtr->err));
-#else
-# ifdef USE_PERLIO
+#ifdef USE_PERLIO
/* For tied filehandles, we apply tiedscalar magic to the IO
slot of the GP rather than the GV itself. */
sv_magic((SV *)GvIOp(request->gv[1]), request->svout, 'q', Nullch, 0);
sv_magic((SV *)GvIOp(request->gv[2]), request->sverr, 'q', Nullch, 0);
sv_magic((SV *)GvIOp(request->gv[0]), request->svin, 'q', Nullch, 0);
-# else
+#else
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);
-# endif
#endif
request->bound = TRUE;
}
been_here = 1;
}
else {
-#ifdef USE_SFIO
- int i;
-#endif
FCGX_Request *fcgx_req = request->requestPtr;
int acceptResult;
populate_env(fcgx_req->envp, request->hvEnv);
-#ifdef USE_SFIO
- for (i = 0; i < 3; ++i) {
- request->io[i] = GvIOn(request->gv[i]);
- if (!(i == 0 ? IoIFP(request->io[i]) : IoOFP(request->io[i]))) {
- IoIFP(request->io[i]) = sftmp(0);
- /*IoIFP(request->io[i]) = sfnew(NULL, NULL, SF_UNBOUND, 0,
- SF_STRING | (i ? SF_WRITE : SF_READ));*/
- if (i != 0)
- IoOFP(request->io[i]) = IoIFP(request->io[i]);
- request->sfcreated[i] = TRUE;
- }
- }
-#else
if (!request->svout) {
newSVrv(request->svout = newSV(0), "FCGI::Stream");
newSVrv(request->sverr = newSV(0), "FCGI::Stream");
sv_setiv(SvRV(request->svout), INT2PTR(IV, fcgx_req->out));
sv_setiv(SvRV(request->sverr), INT2PTR(IV, fcgx_req->err));
sv_setiv(SvRV(request->svin), INT2PTR(IV, fcgx_req->in));
-#endif
FCGI_Bind(request);
request->accepted = TRUE;
}
static void
FCGI_Finish(FCGP_Request* request) {
-#ifdef USE_SFIO
- int i;
-#endif
int was_bound;
dTHX;
if (was_bound = request->bound)
FCGI_UndoBinding(request);
-#ifdef USE_SFIO
- for (i = 0; i < 3; ++i) {
- if (request->sfcreated[i]) {
- sfclose(IoIFP(request->io[i]));
- IoIFP(request->io[i]) = IoOFP(request->io[i]) = Nullfp;
- request->sfcreated[i] = FALSE;
- }
- }
-#endif
if (was_bound)
FCGX_Finish_r(request->requestPtr);
else
MODULE = FCGI PACKAGE = FCGI::Stream
-#ifndef USE_SFIO
-
SV *
PRINT(stream, ...)
FCGI::Stream stream;
RETVAL = FCGX_FClose(stream) != -1;
OUTPUT:
RETVAL
-
-#endif