File Coverage

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


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