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

GOAWAY frame (RFC 7540 Section 6.8) More...

#include <frame.h>

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

Public Member Functions

 goaway_frame (uint32_t last_stream_id, uint32_t error_code, std::vector< uint8_t > additional_data={})
 Construct GOAWAY frame.
 
auto last_stream_id () const -> uint32_t
 Get last stream ID.
 
auto error_code () const -> uint32_t
 Get error code.
 
auto additional_data () const -> std::span< const uint8_t >
 Get additional debug data.
 
- 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< goaway_frame > >
 Parse GOAWAY 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

uint32_t last_stream_id_
 Last stream ID.
 
uint32_t error_code_
 Error code.
 
std::vector< uint8_t > additional_data_
 Debug 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

GOAWAY frame (RFC 7540 Section 6.8)

GOAWAY frames are used to initiate shutdown of a connection or to signal serious error conditions.

Definition at line 386 of file frame.h.

Constructor & Destructor Documentation

◆ goaway_frame()

kcenon::network::protocols::http2::goaway_frame::goaway_frame ( uint32_t last_stream_id,
uint32_t error_code,
std::vector< uint8_t > additional_data = {} )

Construct GOAWAY frame.

Parameters
last_stream_idLast stream ID processed
error_codeError code
additional_dataOptional additional debug data

Definition at line 495 of file frame.cpp.

500 {
501 header_.stream_id = 0;
504
505 auto last_stream_bytes = write_uint32_be(last_stream_id_ & stream_id_mask);
506 payload_.insert(payload_.end(), last_stream_bytes.begin(), last_stream_bytes.end());
507
508 auto error_bytes = write_uint32_be(error_code_);
509 payload_.insert(payload_.end(), error_bytes.begin(), error_bytes.end());
510
511 payload_.insert(payload_.end(), additional_data_.begin(), additional_data_.end());
512
513 header_.length = static_cast<uint32_t>(payload_.size());
514 }
std::vector< uint8_t > payload_
Frame payload.
Definition frame.h:128
frame_header header_
Frame header.
Definition frame.h:127
auto error_code() const -> uint32_t
Get error code.
Definition frame.cpp:547
std::vector< uint8_t > additional_data_
Debug data.
Definition frame.h:428
auto additional_data() const -> std::span< const uint8_t >
Get additional debug data.
Definition frame.cpp:552
uint32_t last_stream_id_
Last stream ID.
Definition frame.h:426
auto last_stream_id() const -> uint32_t
Get last stream ID.
Definition frame.cpp:542
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 additional_data_, error_code_, kcenon::network::protocols::http2::frame_header::flags, kcenon::network::protocols::http2::goaway, kcenon::network::protocols::http2::frame::header_, last_stream_id_, kcenon::network::protocols::http2::frame_header::length, kcenon::network::protocols::http2::frame_flags::none, kcenon::network::protocols::http2::frame::payload_, kcenon::network::protocols::http2::frame_header::stream_id, and kcenon::network::protocols::http2::frame_header::type.

Member Function Documentation

◆ additional_data()

auto kcenon::network::protocols::http2::goaway_frame::additional_data ( ) const -> std::span<const uint8_t>

Get additional debug data.

Returns
Span of additional data

Definition at line 552 of file frame.cpp.

553 {
554 return additional_data_;
555 }

References additional_data_.

◆ error_code()

auto kcenon::network::protocols::http2::goaway_frame::error_code ( ) const -> uint32_t

Get error code.

Returns
Error code

Definition at line 547 of file frame.cpp.

548 {
549 return error_code_;
550 }

References error_code_.

◆ last_stream_id()

auto kcenon::network::protocols::http2::goaway_frame::last_stream_id ( ) const -> uint32_t

Get last stream ID.

Returns
Last stream ID processed

Definition at line 542 of file frame.cpp.

543 {
544 return last_stream_id_;
545 }

References last_stream_id_.

◆ parse()

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

Parse GOAWAY frame from raw bytes.

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

Definition at line 516 of file frame.cpp.

518 {
519 if (hdr.stream_id != 0)
520 {
521 return error_info(17, "GOAWAY frame must have zero stream ID", "http2");
522 }
523
524 if (payload.size() < 8)
525 {
526 return error_info(18, "GOAWAY frame must have at least 8-byte payload", "http2");
527 }
528
529 uint32_t last_stream_id = read_uint32_be(payload.subspan(0, 4)) & stream_id_mask;
530 uint32_t error_code = read_uint32_be(payload.subspan(4, 4));
531
532 std::vector<uint8_t> additional_data;
533 if (payload.size() > 8)
534 {
535 additional_data.assign(payload.begin() + 8, payload.end());
536 }
537
538 return std::make_unique<goaway_frame>(last_stream_id, error_code,
539 std::move(additional_data));
540 }
auto payload() const -> std::span< const uint8_t >
Get frame payload.
Definition frame.cpp:185
simple_error error_info

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

Here is the caller graph for this function:

Member Data Documentation

◆ additional_data_

std::vector<uint8_t> kcenon::network::protocols::http2::goaway_frame::additional_data_
private

Debug data.

Definition at line 428 of file frame.h.

Referenced by additional_data(), and goaway_frame().

◆ error_code_

uint32_t kcenon::network::protocols::http2::goaway_frame::error_code_
private

Error code.

Definition at line 427 of file frame.h.

Referenced by error_code(), and goaway_frame().

◆ last_stream_id_

uint32_t kcenon::network::protocols::http2::goaway_frame::last_stream_id_
private

Last stream ID.

Definition at line 426 of file frame.h.

Referenced by goaway_frame(), and last_stream_id().


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