line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SCGI; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
3823
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
157
|
|
4
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
220
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.6; |
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
2776
|
use SCGI::Request; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
149
|
|
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
50
|
use Carp; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
1442
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
SCGI |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This module is for implementing an SCGI interface for an application server. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPISIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use SCGI; |
23
|
|
|
|
|
|
|
use IO::Socket; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $socket = IO::Socket::INET->new(Listen => 5, ReuseAddr => 1, LocalPort => 8080) |
26
|
|
|
|
|
|
|
or die "cannot bind to port 8080: $!"; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $scgi = SCGI->new($socket, blocking => 1); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
while (my $request = $scgi->accept) { |
31
|
|
|
|
|
|
|
$request->read_env; |
32
|
|
|
|
|
|
|
read $request->connection, my $body, $request->env->{CONTENT_LENGTH}; |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
print $request->connection "Content-Type: text/plain\n\nHello!\n"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 public methods |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item new |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Takes a socket followed by a set of options (key value pairs) and returns a new SCGI listener. Currently the only supported option is blocking, to indicate that the socket blocks and that the library should not treat it accordingly. By default blocking is false. (NOTE: blocking is now a named rather than positional parameter. Using as a positional parameter will produce a warning in this version and will throw an exception in the next version). |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new { |
48
|
4
|
|
|
4
|
1
|
378502
|
my ($class, $socket) = (shift, shift); |
49
|
4
|
50
|
|
|
|
158
|
croak "key without value passed to SCGI->new" |
50
|
|
|
|
|
|
|
if @_ % 2; |
51
|
4
|
|
|
|
|
32
|
my %options = @_; |
52
|
4
|
|
|
|
|
75
|
for my $option (keys %options) { |
53
|
1
|
50
|
|
|
|
23
|
croak "unknown option $option" unless grep $_ eq $option, qw(blocking); |
54
|
|
|
|
|
|
|
} |
55
|
4
|
100
|
|
|
|
127
|
bless {socket => $socket, blocking => $options{blocking} ? 1 : 0}, $class; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item accept |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Accepts a connection from the socket and returns an C> for it. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub accept { |
65
|
14
|
|
|
14
|
1
|
1856
|
my ($this) = @_; |
66
|
14
|
50
|
|
|
|
76
|
my $connection = $this->socket->accept or return; |
67
|
14
|
100
|
|
|
|
16731
|
$connection->blocking(0) unless $this->blocking; |
68
|
14
|
|
|
|
|
287
|
SCGI::Request->_new($connection, $this->blocking); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item socket |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Returns the socket that was passed to the constructor. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub socket { |
78
|
14
|
|
|
14
|
1
|
43
|
my ($this) = @_; |
79
|
14
|
|
|
|
|
198
|
$this->{socket}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item blocking |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Returns true if it was indicated that the socket should be blocking when the SCGI object was created. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub blocking { |
89
|
28
|
|
|
28
|
1
|
55
|
my ($this) = @_; |
90
|
28
|
|
|
|
|
420
|
$this->{blocking}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |