File Coverage

blib/lib/Protocol/HTTP2/Frame/Window_update.pm
Criterion Covered Total %
statement 24 36 66.6
branch 4 12 33.3
condition 0 3 0.0
subroutine 6 6 100.0
pod 0 2 0.0
total 34 59 57.6


line stmt bran cond sub pod time code
1             package Protocol::HTTP2::Frame::Window_update;
2 11     11   57 use strict;
  11         20  
  11         337  
3 11     11   52 use warnings;
  11         20  
  11         311  
4 11     11   52 use Protocol::HTTP2::Constants qw(:flags :errors :limits);
  11         17  
  11         3087  
5 11     11   58 use Protocol::HTTP2::Trace qw(tracer);
  11         17  
  11         3728  
6              
7             sub decode {
8 1     1 0 2 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
9 1         4 my $frame_ref = $con->decode_context->{frame};
10              
11 1 50       4 if ( $length != 4 ) {
12 0         0 tracer->error(
13             "Received windows_update frame with invalid length $length");
14 0         0 $con->error(FRAME_SIZE_ERROR);
15 0         0 return undef;
16             }
17              
18 1         4 my $fcw_add = unpack 'N', substr $$buf_ref, $buf_offset, 4;
19 1         3 $fcw_add &= 0x7FFF_FFFF;
20              
21 1 50       4 if ( $fcw_add == 0 ) {
22 0         0 tracer->error("Received flow-control window increment of 0");
23 0         0 $con->error(PROTOCOL_ERROR);
24 0         0 return undef;
25             }
26              
27 1 50       4 if ( $frame_ref->{stream} == 0 ) {
28 1 50       3 if ( $con->fcw_send($fcw_add) > MAX_FCW_SIZE ) {
29 0         0 $con->error(FLOW_CONTROL_ERROR);
30             }
31             else {
32 1         4 $con->send_blocked();
33             }
34             }
35             else {
36 0         0 my $fcw = $con->stream_fcw_send( $frame_ref->{stream}, $fcw_add );
37 0 0 0     0 if ( defined $fcw && $fcw > MAX_FCW_SIZE ) {
    0          
38 0         0 tracer->warning("flow-control window size exceeded MAX_FCW_SIZE");
39 0         0 $con->stream_error( $frame_ref->{stream}, FLOW_CONTROL_ERROR );
40             }
41             elsif ( defined $fcw ) {
42 0         0 $con->stream_send_blocked( $frame_ref->{stream} );
43             }
44             }
45 1         5 return $length;
46             }
47              
48             sub encode {
49 1     1 0 3 my ( $con, $flags_ref, $stream, $data ) = @_;
50 1         4 return pack 'N', $data;
51             }
52              
53             1;