line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2010-2011 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Async::FastCGI::Protocol; |
7
|
|
|
|
|
|
|
|
8
|
17
|
|
|
17
|
|
100
|
use strict; |
|
17
|
|
|
|
|
37
|
|
|
17
|
|
|
|
|
589
|
|
9
|
17
|
|
|
17
|
|
89
|
use warnings; |
|
17
|
|
|
|
|
31
|
|
|
17
|
|
|
|
|
606
|
|
10
|
|
|
|
|
|
|
|
11
|
17
|
|
|
17
|
|
86
|
use base qw( IO::Async::Protocol::Stream ); |
|
17
|
|
|
|
|
27
|
|
|
17
|
|
|
|
|
16029
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
14
|
|
|
|
|
|
|
|
15
|
17
|
|
|
|
|
1795
|
use Net::FastCGI::Constant qw( |
16
|
|
|
|
|
|
|
FCGI_UNKNOWN_TYPE |
17
|
17
|
|
|
17
|
|
65026
|
); |
|
17
|
|
|
|
|
19452
|
|
18
|
|
|
|
|
|
|
|
19
|
17
|
|
|
|
|
7121
|
use Net::FastCGI::Protocol qw( |
20
|
|
|
|
|
|
|
parse_header |
21
|
|
|
|
|
|
|
build_record |
22
|
|
|
|
|
|
|
build_unknown_type_body |
23
|
17
|
|
|
17
|
|
19510
|
); |
|
17
|
|
|
|
|
144025
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub on_read |
26
|
|
|
|
|
|
|
{ |
27
|
90
|
|
|
90
|
1
|
31732
|
my $self = shift; |
28
|
90
|
|
|
|
|
172
|
my ( $buffref, $handleclosed ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
90
|
|
|
|
|
204
|
my $blen = length $$buffref; |
31
|
|
|
|
|
|
|
|
32
|
90
|
100
|
|
|
|
299
|
if( $handleclosed ) { |
33
|
|
|
|
|
|
|
# Abort |
34
|
1
|
|
|
|
|
3
|
my $fcgi = $self->{fcgi}; |
35
|
1
|
|
|
|
|
13
|
$fcgi->remove_child( $self ); |
36
|
1
|
|
|
|
|
293
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Do we have a record header yet? |
40
|
89
|
50
|
|
|
|
293
|
return 0 unless( $blen >= 8 ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Excellent - parse it |
43
|
89
|
|
|
|
|
327
|
my ( $type, $reqid, $contentlen, $padlen ) = parse_header( $$buffref ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Do we have enough for a complete record? |
46
|
89
|
50
|
|
|
|
1048
|
return 0 unless( $blen >= 8 + $contentlen + $padlen ); |
47
|
|
|
|
|
|
|
|
48
|
89
|
|
|
|
|
176
|
substr( $$buffref, 0, 8, "" ); # Header |
49
|
|
|
|
|
|
|
|
50
|
89
|
|
|
|
|
349
|
my $rec = { |
51
|
|
|
|
|
|
|
type => $type, |
52
|
|
|
|
|
|
|
reqid => $reqid, |
53
|
|
|
|
|
|
|
len => $contentlen, |
54
|
|
|
|
|
|
|
plen => $padlen, |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
89
|
|
|
|
|
282
|
$rec->{content} = substr( $$buffref, 0, $contentlen, "" ); |
58
|
|
|
|
|
|
|
|
59
|
89
|
|
|
|
|
157
|
substr( $$buffref, 0, $rec->{plen}, "" ); # Padding |
60
|
|
|
|
|
|
|
|
61
|
89
|
100
|
|
|
|
234
|
if( $reqid == 0 ) { |
62
|
4
|
|
|
|
|
25
|
$self->on_mgmt_record( $type, $rec ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
85
|
|
|
|
|
365
|
$self->on_record( $reqid, $rec ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
89
|
|
|
|
|
1382
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub on_mgmt_record |
72
|
|
|
|
|
|
|
{ |
73
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
74
|
1
|
|
|
|
|
2
|
my ( $type, $rec ) = @_; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
6
|
$self->write_record( { type => FCGI_UNKNOWN_TYPE, reqid => 0 }, build_unknown_type_body( $type ) ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub write_record |
80
|
|
|
|
|
|
|
{ |
81
|
71
|
|
|
71
|
0
|
322
|
my $self = shift; |
82
|
71
|
|
|
|
|
109
|
my ( $rec, $content ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
71
|
|
|
|
|
284
|
$self->write( build_record( $rec->{type}, $rec->{reqid}, $content ) ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
0x55AA; |