1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
5 FCGI_Accept(2) Man Page
7 <STYLE TYPE="text/css">
9 background-color: #ffffff;
11 li.c2 {list-style: none}
12 div.c1 {text-align: center}
16 <A HREF="cover.htm">[Top]</A> <A HREF="ch4tcl.htm">[Prev]</A> <A HREF="ap_guida.htm">[Next]</A> <A HREF=
17 "ap_guida.htm">[Bottom]</A>
29 This appendix contains reference pages for the following FastCGI routines from the <CODE>fcgi_stdio</CODE>
39 <CODE>FCGI_Accept</CODE> <A NAME="95885"></A>
42 <CODE>FCGI_Start_Filter_Data</CODE> <A NAME="95859"></A>
45 <CODE>FCGI_SetExitStatus</CODE>
54 <A NAME="95637"></A> <CODE>FCGI_Accept, FCGI_ToFILE, FCGI_ToFcgiStream</CODE>
56 - fcgi_stdio compatibility library
64 <A NAME="95669">#include <fcgi_stdio.h>
66 <A NAME="95653">int<BR>
69 <A NAME="95654">FILE *<BR>
70 FCGI_ToFILE(FCGI_FILE *);
72 <A NAME="95655">FCGI_Stream *<BR>
73 FCGI_ToFcgiStream(FCGI_FILE *);
81 The FCGI_Accept function accepts a new request from the HTTP server and creates a CGI-compatible execution
82 environment for the request.
85 <A NAME="95657"></A> If the application was invoked as a CGI program, the first call to FCGI_Accept is
86 essentially a no-op and the second call returns -1. This causes a correctly coded FastCGI application to run a
87 single request and exit, giving CGI behavior.
90 <A NAME="95658"></A> If the application was invoked as a FastCGI server, the first call to FCGI_Accept
91 indicates that the application has completed its initialization and is ready to accept its first request.
92 Subsequent calls to FCGI_Accept indicate that the application has completed processing its current request and
93 is ready to accept a new request.
96 <A NAME="95659"></A> In completing the current request, FCGI_Accept may detect errors, such as a broken pipe
97 to a client who has disconnected early. FCGI_Accept ignores such errors. An application that wishes to handle
98 such errors should explicitly call fclose(stderr), then fclose(stdout); an EOF return from either one
102 <A NAME="95660"></A> After accepting a new request, FCGI_Accept assigns new values to the global variables
103 stdin, stdout, stderr, and environ. After FCGI_Accept returns, these variables have the same interpretation as
104 on entry to a CGI program.
107 <A NAME="95661"></A> In addition to the standard CGI environment variables, the environment variable
108 <CODE>FCGI_ROLE</CODE> is always set to the role of the current request. The roles currently defined are
109 <CODE>RESPONDER, AUTHORIZER</CODE>, and <CODE>FILTER</CODE>.
112 <A NAME="95662"></A> In the <CODE>FILTER</CODE> role, the additional variables <CODE>FCGI_DATA_LENGTH</CODE>
113 and <CODE>FCGI_DATA_LAST_MOD</CODE> are also defined. See <CODE>FCGI_StartFilterData</CODE><CODE>(3</CODE>)
114 for complete information.
117 <A NAME="95663"></A> The macros <CODE>FCGI_ToFILE</CODE> and <CODE>FCGI_ToFcgiStream</CODE> are provided to
118 allow escape to native functions that use the types <CODE>FILE</CODE> or <CODE>FCGI_Stream</CODE>. In the case
119 of <CODE>FILE</CODE>, functions would have to be separately compiled, since <CODE>fcgi_stdio.h</CODE> replaces
120 the standard <CODE>FILE</CODE> with <CODE>FCGI_FILE</CODE>.
129 0 for successful call, -1 for error (application should exit).
134 FCGI_StartFilterData (3)
139 <A NAME="95311"></A> <CODE>FCGI_StartFilterData</CODE>
141 -<CODE>fcgi_stdio</CODE> compatibility library
149 <A NAME="95313">#include <fcgi_stdio.h>
151 <A NAME="95314">int FCGI_StartFilterData(void)
159 Enables a FastCGI Filter application to begin reading its filter input data from <CODE>stdin</CODE>.
162 <A NAME="95729"></A> In order to call <CODE>FCGI_StartFilterData</CODE>, the FastCGI application should have
163 been invoked in the filter role (<CODE>getenv("FCGI_ROLE") == "FILTER"</CODE>), and should
164 have read <CODE>stdin</CODE> to EOF, consuming the entire <CODE>FCGI_STDIN</CODE> data stream. The call to
165 <CODE>FCGI_StartFilterData</CODE> positions stdin at the start of <CODE>FCGI_DATA</CODE>.
168 <A NAME="95730"></A> If the preconditions are not met (e.g., the application has not read <CODE>stdin</CODE>
169 to EOF), <CODE>FCGI_StartFilterData</CODE> returns a negative result, and the application will get EOF on
170 attempts to read from <CODE>stdin</CODE>.
173 <A NAME="95731"></A> The application can determine the number of bytes available on <CODE>FCGI_DATA</CODE> by
174 performing <CODE>atoi(getenv("FCGI_DATA_LENGTH")</CODE>. If fewer than this many bytes are delivered
175 on <CODE>stdin</CODE> after calling <CODE>FCGI_StartFilterData</CODE>, the application should perform an
176 application-specific error response. If the application normally makes an update, most likely it should abort
180 <A NAME="95732"></A> The application can determine last modification time of the filter input data by
181 performing <CODE>getenv("FCGI_DATA_LAST_MOD").</CODE> This allows applications to perform caching
182 based on last modification time.
191 Returns 0 on success and a negative integer on failure.
200 The following example reads in all the client data, but ignores it. Then, the code calls
201 <CODE>FCGI_StartFilterData</CODE>. Finally, the code reads in the file to be filtered and simply echos it back
207 <A NAME="95324">while (FCGI_Accept() >= 0) {
211 <A NAME="95364">/* Read data passed by client. */
213 <A NAME="95358"> while (getchar () != OF)
221 <A NAME="95367">/* Adjust standard input stream. */
223 <A NAME="95366"> status = FCGI_StartFilterData();
227 <A NAME="95360">/* Read in filter data and echo it back to client. */
229 <A NAME="95368"> while ((len = fread(tempBuffer, 1, 1024, stdin)) > 0)
231 <A NAME="95361"> fwrite(tempBuffer, 1, len, stdout);
235 <A NAME="95845">} /* End FCGI_Accept loop */
239 FCGI_SetExitStatus(3)
244 <A NAME="95794"></A> <CODE>FCGI_SetExitStatus</CODE>
246 - <CODE>fcgi_stdio</CODE> compatibility library
254 <A NAME="95795">#include <fcgi_stdio.h>
256 <A NAME="95787">void FCGI_SetExitStatus(int status);
264 Sets the exit status for the current FastCGI request. The exit status is the status code the request would
265 have exited with, had the request been run as a CGI program.
268 <A NAME="95789"></A> You can call <CODE>FCGI_SetExitStatus</CODE> several times during a request; the last
269 call before the request ends determines the value.
278 <A HREF="cover.htm">[Top]</A> <A HREF="ch4tcl.htm">[Prev]</A> <A HREF="ap_guida.htm">[Next]</A> <A HREF=
279 "ap_guida.htm">[Bottom]</A>
282 <!-- This file was created with Quadralay WebWorks Publisher 3.0.3 -->
284 <!-- For more information on how this document, and how the rest of -->
285 <!-- this server was created, email yourEmail@xyzcorp.com -->
287 <!-- Last updated: 04/15/96 08:00:20 -->