File: Ping.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 (38 lines) | stat: -rw-r--r-- 901 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
package Protocol::HTTP2::Frame::Ping;
use strict;
use warnings;
use Protocol::HTTP2::Constants qw(:flags :errors :limits);
use Protocol::HTTP2::Trace qw(tracer);

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

    # PING associated with connection
    if ( $frame_ref->{stream} != 0 ) {
        $con->error(PROTOCOL_ERROR);
        return undef;
    }

    # payload is 8 octets
    if ( $length != PING_PAYLOAD_SIZE ) {
        $con->error(FRAME_SIZE_ERROR);
        return undef;
    }

    $con->ack_ping( \substr $$buf_ref, $buf_offset, $length )
      unless $frame_ref->{flags} & ACK;

    return $length;
}

sub encode {
    my ( $con, $flags_ref, $stream, $data_ref ) = @_;
    if ( length($$data_ref) != PING_PAYLOAD_SIZE ) {
        $con->error(INTERNAL_ERROR);
        return undef;
    }
    return $$data_ref;
}

1;