Commit | Line | Data |
794c66be |
1 | # $Id: FCGI.pm,v 1.9 2000/04/21 18:10:53 skimo Exp $ |
1b64d24d |
2 | |
3 | package FCGI; |
4 | |
5 | require Exporter; |
6 | require DynaLoader; |
7 | |
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. |
12 | @EXPORT = qw( |
13 | |
14 | ); |
15 | |
794c66be |
16 | $VERSION = '0.52'; |
1b64d24d |
17 | |
18 | bootstrap FCGI; |
19 | |
20 | # Preloaded methods go here. |
21 | |
22 | # Autoload methods go after __END__, and are processed by the autosplit program. |
23 | |
d2900ee8 |
24 | *FAIL_ACCEPT_ON_INTR = sub() { 1 }; |
25 | |
6ff77aff |
26 | sub Request(;***$$$) { |
27 | my @defaults = (\*STDIN, \*STDOUT, \*STDERR, \%ENV, 0, 0); |
28 | splice @defaults,0,@_,@_; |
29 | RequestX(@defaults); |
d8cc97fb |
30 | } |
31 | |
6ff77aff |
32 | sub accept() { |
d8cc97fb |
33 | if (defined %FCGI::ENV) { |
34 | %ENV = %FCGI::ENV; |
35 | } else { |
36 | %FCGI::ENV = %ENV; |
37 | } |
6ff77aff |
38 | my $rc = Accept($global_request); |
39 | for (keys %FCGI::ENV) { |
40 | $ENV{$_} = $FCGI::ENV{$_} unless exists $ENV{$_}; |
41 | } |
d8cc97fb |
42 | |
43 | # not SFIO |
44 | $SIG{__WARN__} = $SIG{__DIE__} = $warn_die_handler if (tied (*STDIN)); |
45 | |
46 | return $rc; |
47 | } |
48 | |
6ff77aff |
49 | sub finish() { |
d8cc97fb |
50 | %ENV = %FCGI::ENV if (defined %FCGI::ENV); |
51 | |
52 | # not SFIO |
53 | if (tied (*STDIN)) { |
54 | for (qw(__WARN__ __DIE__)) { |
55 | delete $SIG{$_} if ($SIG{$_} == $warn_die_handler); |
56 | } |
57 | } |
58 | |
59 | Finish ($global_request); |
60 | } |
61 | |
6ff77aff |
62 | sub flush() { |
d8cc97fb |
63 | Flush($global_request); |
64 | } |
65 | |
5baeeca7 |
66 | sub detach() { |
67 | Detach($global_request); |
68 | } |
69 | |
70 | sub attach() { |
71 | Attach($global_request); |
72 | } |
73 | |
d8cc97fb |
74 | # deprecated |
75 | sub set_exit_status { |
76 | } |
77 | |
6ff77aff |
78 | sub start_filter_data() { |
d8cc97fb |
79 | StartFilterData($global_request); |
80 | } |
81 | |
82 | $global_request = Request(); |
6c4b41b7 |
83 | $warn_die_handler = sub { print STDERR @_ unless $^S }; |
d8cc97fb |
84 | |
85 | package FCGI::Stream; |
86 | |
1b64d24d |
87 | sub PRINTF { |
88 | shift->PRINT(sprintf(shift, @_)); |
89 | } |
90 | |
91 | 1; |
92 | |
d2900ee8 |
93 | =pod |
94 | |
1b64d24d |
95 | =head1 NAME |
96 | |
97 | FCGI - Fast CGI module |
98 | |
99 | =head1 SYNOPSIS |
100 | |
101 | use FCGI; |
102 | |
d2900ee8 |
103 | my $count = 0; |
104 | my $request = FCGI::Request(); |
105 | |
106 | while($request->accept() >= 0) { |
1b64d24d |
107 | print("Content-type: text/html\r\n\r\n", ++$count); |
108 | } |
109 | |
110 | =head1 DESCRIPTION |
111 | |
112 | Functions: |
113 | |
114 | =over 4 |
115 | |
d2900ee8 |
116 | =item FCGI::Request |
117 | |
118 | Creates a request handle. It has the following optional parameters: |
119 | |
120 | =over 8 |
121 | |
122 | =item input perl file handle (default: \*STDIN) |
123 | |
124 | =item output perl file handle (default: \*STDOUT) |
125 | |
126 | =item error perl file handle (default: \*STDERR) |
127 | |
128 | These filehandles will be setup to act as input/output/error |
129 | on succesful Accept. |
130 | |
131 | =item environment hash reference (default: \%ENV) |
132 | |
133 | The hash will be populated with the environment. |
134 | |
135 | =item socket (default: 0) |
136 | |
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. |
141 | |
142 | =item flags (default: 0) |
143 | |
144 | Possible values: |
1b64d24d |
145 | |
d2900ee8 |
146 | =over 12 |
147 | |
148 | =item FCGI::FAIL_ACCEPT_ON_INTR |
149 | |
150 | If set, Accept will fail if interrupted. |
151 | It not set, it will just keep on waiting. |
152 | |
153 | =back |
154 | |
155 | =back |
156 | |
157 | Example usage: |
158 | my $req = FCGI::Request; |
159 | |
160 | or: |
161 | my %env; |
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); |
166 | |
167 | =item FCGI::OpenSocket(path, backlog) |
168 | |
169 | =item FCGI::CloseSocket(socket) |
170 | |
171 | Close a socket opened with OpenSocket. |
172 | |
173 | =item $req->Accept() |
174 | |
175 | Accepts a connection on $req, attaching the filehandles and |
176 | populating the environment hash. |
177 | Returns 0 on success. |
1b64d24d |
178 | If a connection has been accepted before, the old |
179 | one will be finished first. |
180 | |
d2900ee8 |
181 | Note that unlike with the old interface, no die and warn |
182 | handlers are installed by default. |
183 | |
184 | =item $req->Finish() |
1b64d24d |
185 | |
186 | Finishes accepted connection. |
d2900ee8 |
187 | Also detaches filehandles. |
1b64d24d |
188 | |
d2900ee8 |
189 | =item $req->Flush() |
1b64d24d |
190 | |
191 | Flushes accepted connection. |
192 | |
d2900ee8 |
193 | =item $req->Detach() |
1b64d24d |
194 | |
d2900ee8 |
195 | Temporarily detaches filehandles on an accepted connection. |
1b64d24d |
196 | |
d2900ee8 |
197 | =item $req->Attach() |
1b64d24d |
198 | |
d2900ee8 |
199 | Re-attaches filehandles on an accepted connection. |
1b64d24d |
200 | |
201 | =back |
202 | |
203 | =head1 AUTHOR |
204 | |
205 | Sven Verdoolaege <skimo@kotnet.org> |
206 | |
207 | =cut |
208 | |
209 | __END__ |