File: Goaway.pm

package info (click to toggle)
libprotocol-http2-perl 1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 448 kB
  • sloc: perl: 3,370; makefile: 7
file content (48 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package Protocol::HTTP2::Frame::Goaway;
use strict;
use warnings;
use Protocol::HTTP2::Constants qw(const_name :flags :errors);
use Protocol::HTTP2::Trace qw(tracer bin2hex);

sub decode {
    my ( $con, $buf_ref, $buf_offset, $length ) = @_;
    my $frame_ref = $con->decode_context->{frame};

    if ( $frame_ref->{stream} != 0 ) {
        $con->error(PROTOCOL_ERROR);
        return undef;
    }

    my ( $last_stream_id, $error_code ) =
      unpack( 'N2', substr( $$buf_ref, $buf_offset, 8 ) );

    $last_stream_id &= 0x7FFF_FFFF;

    tracer->debug( "GOAWAY with error code "
          . const_name( 'errors', $error_code )
          . " last stream is $last_stream_id\n" );

    tracer->debug( "additional debug data: "
          . bin2hex( substr( $$buf_ref, $buf_offset + 8 ) )
          . "\n" )
      if $length - 8 > 0;

    $con->goaway(1);

    return $length;
}

sub encode {
    my ( $con, $flags_ref, $stream, $data ) = @_;

    $con->goaway(1);

    my $payload = pack( 'N2', @$data );
    tracer->debug( "\tGOAWAY: last stream = $data->[0], error = "
          . const_name( "errors", $data->[1] )
          . "\n" );
    $payload .= $data->[2] if @$data > 2;
    return $payload;
}

1;