File: Rst_stream.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 (40 lines) | stat: -rw-r--r-- 1,078 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
package Protocol::HTTP2::Frame::Rst_stream;
use strict;
use warnings;
use Protocol::HTTP2::Constants qw(const_name :flags :errors);
use Protocol::HTTP2::Trace qw(tracer);

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

    # RST_STREAM associated with stream
    if ( $frame_ref->{stream} == 0 ) {
        tracer->error("Received reset stream with stream id 0");
        $con->error(PROTOCOL_ERROR);
        return undef;
    }

    if ( $length != 4 ) {
        tracer->error("Received reset stream with invalid length $length");
        $con->error(FRAME_SIZE_ERROR);
        return undef;
    }

    my $code = unpack( 'N', substr( $$buf_ref, $buf_offset, 4 ) );

    tracer->debug( "Receive reset stream with error code "
          . const_name( "errors", $code )
          . "\n" );
    $con->stream_reset( $frame_ref->{stream}, $code );

    return $length;
}

sub encode {
    my ( $con, $flags_ref, $stream, $data ) = @_;
    $con->stream_reset( $stream, $data );
    return pack 'N', $data;
}

1;