| 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-2024 -- leonerd@leonerd.org.uk | ||||||||||
| 5 | |||||||||||
| 6 | package Net::Async::FastCGI::Protocol 0.26; | ||||||||||
| 7 | |||||||||||
| 8 | 18 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 18 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 18 | ▶ | use base qw( IO::Async::Protocol::Stream ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 18 | ▶ | use Net::FastCGI::Constant qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | FCGI_UNKNOWN_TYPE | ||||||||||
| 15 | 18 | ); | |||||||||
| 16 | |||||||||||
| 17 | 18 | ▶ | use Net::FastCGI::Protocol qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | parse_header | ||||||||||
| 19 | build_record | ||||||||||
| 20 | build_unknown_type_body | ||||||||||
| 21 | 18 | ); | |||||||||
| 22 | |||||||||||
| 23 | sub on_read | ||||||||||
| 24 | 103 | ▶ | { | ||||||||
|
Subroutine
on_read: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 25 | 103 | my $self = shift; | |||||||||
| 26 | 103 | my ( $buffref, $handleclosed ) = @_; | |||||||||
| 27 | |||||||||||
| 28 | 103 | my $blen = length $$buffref; | |||||||||
| 29 | |||||||||||
| 30 | 103 | ▶ | if( $handleclosed ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | # Abort | ||||||||||
| 32 | 1 | my $fcgi = $self->{fcgi}; | |||||||||
| 33 | 1 | $fcgi->remove_child( $self ); | |||||||||
| 34 | 1 | return; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | # Do we have a record header yet? | ||||||||||
| 38 | 102 | ▶ | return 0 unless( $blen >= 8 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | # Excellent - parse it | ||||||||||
| 41 | 102 | my ( $type, $reqid, $contentlen, $padlen ) = parse_header( $$buffref ); | |||||||||
| 42 | |||||||||||
| 43 | # Do we have enough for a complete record? | ||||||||||
| 44 | 102 | ▶ | return 0 unless( $blen >= 8 + $contentlen + $padlen ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 102 | substr( $$buffref, 0, 8, "" ); # Header | |||||||||
| 47 | |||||||||||
| 48 | 102 | my $rec = { | |||||||||
| 49 | type => $type, | ||||||||||
| 50 | reqid => $reqid, | ||||||||||
| 51 | len => $contentlen, | ||||||||||
| 52 | plen => $padlen, | ||||||||||
| 53 | }; | ||||||||||
| 54 | |||||||||||
| 55 | 102 | $rec->{content} = substr( $$buffref, 0, $contentlen, "" ); | |||||||||
| 56 | |||||||||||
| 57 | 102 | substr( $$buffref, 0, $rec->{plen}, "" ); # Padding | |||||||||
| 58 | |||||||||||
| 59 | 102 | ▶ | if( $reqid == 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 4 | $self->on_mgmt_record( $type, $rec ); | |||||||||
| 61 | } | ||||||||||
| 62 | else { | ||||||||||
| 63 | 98 | $self->on_record( $reqid, $rec ); | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 102 | return 1; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | sub on_mgmt_record | ||||||||||
| 70 | 1 | ▶ | { | ||||||||
|
Subroutine
on_mgmt_record: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 71 | 1 | my $self = shift; | |||||||||
| 72 | 1 | my ( $type, $rec ) = @_; | |||||||||
| 73 | |||||||||||
| 74 | 1 | $self->write_record( { type => FCGI_UNKNOWN_TYPE, reqid => 0 }, build_unknown_type_body( $type ) ); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | sub write_record | ||||||||||
| 78 | 71 | ▶ | { | ||||||||
|
Subroutine
write_record: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 79 | 71 | my $self = shift; | |||||||||
| 80 | 71 | my ( $rec, $content ) = @_; | |||||||||
| 81 | |||||||||||
| 82 | 71 | $self->write( build_record( $rec->{type}, $rec->{reqid}, $content ) ); | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 18 | 0x55AA; | |||||||||