Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::protocols::http2::ping_frame Class Reference

PING frame (RFC 7540 Section 6.7) More...

#include <frame.h>

Inheritance diagram for kcenon::network::protocols::http2::ping_frame:
Inheritance graph
Collaboration diagram for kcenon::network::protocols::http2::ping_frame:
Collaboration graph

Public Member Functions

 ping_frame (std::array< uint8_t, 8 > opaque_data={}, bool ack=false)
 Construct PING frame.
 
auto opaque_data () const -> const std::array< uint8_t, 8 > &
 Get opaque data.
 
auto is_ack () const -> bool
 Check if this is an ACK frame.
 
- Public Member Functions inherited from kcenon::network::protocols::http2::frame
 frame ()=default
 Default constructor.
 
 frame (const frame_header &hdr, std::vector< uint8_t > payload)
 Construct frame with header and payload.
 
auto serialize () const -> std::vector< uint8_t >
 Serialize frame to bytes.
 
auto header () const -> const frame_header &
 Get frame header.
 
auto payload () const -> std::span< const uint8_t >
 Get frame payload.
 
virtual ~frame ()=default
 Virtual destructor.
 

Static Public Member Functions

static auto parse (const frame_header &hdr, std::span< const uint8_t > payload) -> Result< std::unique_ptr< ping_frame > >
 Parse PING frame from raw bytes.
 
- Static Public Member Functions inherited from kcenon::network::protocols::http2::frame
static auto parse (std::span< const uint8_t > data) -> Result< std::unique_ptr< frame > >
 Parse frame from raw bytes.
 

Private Attributes

std::array< uint8_t, 8 > opaque_data_
 8-byte opaque data
 

Additional Inherited Members

- Protected Attributes inherited from kcenon::network::protocols::http2::frame
frame_header header_
 Frame header.
 
std::vector< uint8_t > payload_
 Frame payload.
 

Detailed Description

PING frame (RFC 7540 Section 6.7)

PING frames are a mechanism for measuring a minimal round-trip time from the sender and for determining whether an idle connection is still functional.

Definition at line 343 of file frame.h.

Constructor & Destructor Documentation

◆ ping_frame()

kcenon::network::protocols::http2::ping_frame::ping_frame ( std::array< uint8_t, 8 > opaque_data = {},
bool ack = false )
explicit

Construct PING frame.

Parameters
opaque_data8-byte opaque data
ackTrue if this is an acknowledgment

Definition at line 455 of file frame.cpp.

457 {
458 header_.stream_id = 0;
461 header_.length = 8;
462
463 payload_.assign(opaque_data_.begin(), opaque_data_.end());
464 }
std::vector< uint8_t > payload_
Frame payload.
Definition frame.h:128
frame_header header_
Frame header.
Definition frame.h:127
auto opaque_data() const -> const std::array< uint8_t, 8 > &
Get opaque data.
Definition frame.cpp:485
std::array< uint8_t, 8 > opaque_data_
8-byte opaque data
Definition frame.h:376
uint32_t stream_id
Stream identifier (31 bits, MSB reserved)
Definition frame.h:58
uint32_t length
Payload length (24 bits)
Definition frame.h:55

References kcenon::network::protocols::http2::frame_flags::ack, kcenon::network::protocols::http2::frame_header::flags, kcenon::network::protocols::http2::frame::header_, kcenon::network::protocols::http2::frame_header::length, kcenon::network::protocols::http2::frame_flags::none, opaque_data_, kcenon::network::protocols::http2::frame::payload_, kcenon::network::protocols::http2::ping, kcenon::network::protocols::http2::frame_header::stream_id, and kcenon::network::protocols::http2::frame_header::type.

Member Function Documentation

◆ is_ack()

auto kcenon::network::protocols::http2::ping_frame::is_ack ( ) const -> bool

Check if this is an ACK frame.

Returns
True if ACK flag is set

Definition at line 490 of file frame.cpp.

491 {
493 }

References kcenon::network::protocols::http2::frame_flags::ack, kcenon::network::protocols::http2::frame_header::flags, and kcenon::network::protocols::http2::frame::header_.

◆ opaque_data()

auto kcenon::network::protocols::http2::ping_frame::opaque_data ( ) const -> const std::array<uint8_t, 8>&

Get opaque data.

Returns
8-byte opaque data

Definition at line 485 of file frame.cpp.

486 {
487 return opaque_data_;
488 }

References opaque_data_.

◆ parse()

auto kcenon::network::protocols::http2::ping_frame::parse ( const frame_header & hdr,
std::span< const uint8_t > payload ) -> Result<std::unique_ptr<ping_frame>>
static

Parse PING frame from raw bytes.

Parameters
hdrFrame header (must be PING type)
payloadFrame payload
Returns
Result containing parsed PING frame or error

Definition at line 466 of file frame.cpp.

468 {
469 if (hdr.stream_id != 0)
470 {
471 return error_info(15, "PING frame must have zero stream ID", "http2");
472 }
473
474 if (payload.size() != 8)
475 {
476 return error_info(16, "PING frame must have 8-byte payload", "http2");
477 }
478
479 std::array<uint8_t, 8> opaque_data;
480 std::copy_n(payload.begin(), 8, opaque_data.begin());
481
482 return std::make_unique<ping_frame>(opaque_data, hdr.flags & frame_flags::ack);
483 }
auto payload() const -> std::span< const uint8_t >
Get frame payload.
Definition frame.cpp:185
simple_error error_info

References kcenon::network::protocols::http2::frame_flags::ack.

Referenced by kcenon::network::protocols::http2::frame::parse().

Here is the caller graph for this function:

Member Data Documentation

◆ opaque_data_

std::array<uint8_t, 8> kcenon::network::protocols::http2::ping_frame::opaque_data_
private

8-byte opaque data

Definition at line 376 of file frame.h.

Referenced by opaque_data(), and ping_frame().


The documentation for this class was generated from the following files: