|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
QUIC stream implementation (RFC 9000 Sections 2-4) More...
#include <stream.h>

Public Member Functions | |
| stream (uint64_t id, bool is_local, uint64_t initial_max_data=65536) | |
| Construct a stream. | |
| ~stream ()=default | |
| stream (const stream &)=delete | |
| auto | operator= (const stream &) -> stream &=delete |
| stream (stream &&) noexcept=default | |
| auto | operator= (stream &&) noexcept -> stream &=default |
| auto | id () const noexcept -> uint64_t |
| Get stream identifier. | |
| auto | is_local () const noexcept -> bool |
| Check if stream is locally initiated. | |
| auto | is_unidirectional () const noexcept -> bool |
| Check if stream is unidirectional. | |
| auto | is_bidirectional () const noexcept -> bool |
| Check if stream is bidirectional. | |
| auto | send_state () const noexcept -> send_stream_state |
| Get send state. | |
| auto | can_send () const noexcept -> bool |
| Check if stream can send data. | |
| auto | write (std::span< const uint8_t > data) -> Result< size_t > |
| Write data to stream. | |
| auto | finish () -> VoidResult |
| Mark stream as finished (send FIN) | |
| auto | reset (uint64_t error_code) -> VoidResult |
| Reset the stream with error code. | |
| auto | fin_sent () const noexcept -> bool |
| Check if FIN has been sent. | |
| auto | pending_bytes () const noexcept -> size_t |
| Get number of bytes pending to send. | |
| auto | next_stream_frame (size_t max_size) -> std::optional< stream_frame > |
| Get next STREAM frame to send. | |
| void | acknowledge_data (uint64_t offset, uint64_t length) |
| Acknowledge sent data. | |
| auto | recv_state () const noexcept -> recv_stream_state |
| Get receive state. | |
| auto | has_data () const noexcept -> bool |
| Check if stream has data to read. | |
| auto | read (std::span< uint8_t > buffer) -> Result< size_t > |
| Read data from stream. | |
| auto | is_fin_received () const noexcept -> bool |
| Check if all data has been received. | |
| auto | stop_sending (uint64_t error_code) -> VoidResult |
| Signal that incoming data is no longer wanted. | |
| auto | receive_data (uint64_t offset, std::span< const uint8_t > data, bool fin) -> VoidResult |
| Receive STREAM frame data. | |
| auto | receive_reset (uint64_t error_code, uint64_t final_size) -> VoidResult |
| Handle received RESET_STREAM frame. | |
| auto | receive_stop_sending (uint64_t error_code) -> VoidResult |
| Handle received STOP_SENDING frame. | |
| void | set_max_send_data (uint64_t max) |
| Set peer's MAX_STREAM_DATA (our send limit) | |
| auto | max_send_data () const noexcept -> uint64_t |
| Get peer's MAX_STREAM_DATA. | |
| auto | available_send_window () const noexcept -> size_t |
| Get available send window. | |
| void | set_max_recv_data (uint64_t max) |
| Update our MAX_STREAM_DATA (peer's send limit) | |
| auto | max_recv_data () const noexcept -> uint64_t |
| Get our MAX_STREAM_DATA. | |
| auto | bytes_consumed () const noexcept -> uint64_t |
| Get bytes consumed from receive buffer. | |
| auto | should_send_max_stream_data () const noexcept -> bool |
| Check if MAX_STREAM_DATA frame should be sent. | |
| auto | generate_max_stream_data () -> std::optional< uint64_t > |
| Generate MAX_STREAM_DATA frame if needed. | |
| auto | reset_error_code () const noexcept -> std::optional< uint64_t > |
| Get reset error code (if stream was reset) | |
| auto | stop_sending_error_code () const noexcept -> std::optional< uint64_t > |
| Get stop sending error code (if STOP_SENDING received) | |
Private Member Functions | |
| void | reassemble_data () |
| void | update_send_state () |
| void | update_recv_state () |
Private Attributes | |
| uint64_t | id_ |
| bool | is_local_ |
| send_stream_state | send_state_ {send_stream_state::ready} |
| std::deque< uint8_t > | send_buffer_ |
| uint64_t | send_offset_ {0} |
| uint64_t | acked_offset_ {0} |
| bool | fin_sent_ {false} |
| bool | fin_acked_ {false} |
| recv_stream_state | recv_state_ {recv_stream_state::recv} |
| std::map< uint64_t, std::vector< uint8_t > > | recv_buffer_ |
| std::deque< uint8_t > | recv_ready_ |
| uint64_t | recv_offset_ {0} |
| bool | recv_fin_ {false} |
| std::optional< uint64_t > | final_size_ |
| uint64_t | max_send_offset_ {0} |
| uint64_t | max_recv_offset_ {65536} |
| uint64_t | recv_window_size_ {65536} |
| std::optional< uint64_t > | reset_error_code_ |
| std::optional< uint64_t > | stop_sending_error_code_ |
Static Private Attributes | |
| static constexpr double | window_update_threshold_ {0.5} |
QUIC stream implementation (RFC 9000 Sections 2-4)
A QUIC stream is an ordered, reliable, bidirectional or unidirectional byte stream within a QUIC connection.
|
explicit |
Construct a stream.
| id | Stream identifier |
| is_local | True if locally initiated |
| initial_max_data | Initial flow control limit |
Definition at line 13 of file stream.cpp.
|
default |
|
delete |
|
defaultnoexcept |
| void kcenon::network::protocols::quic::stream::acknowledge_data | ( | uint64_t | offset, |
| uint64_t | length ) |
Acknowledge sent data.
| offset | Start offset of acknowledged data |
| length | Length of acknowledged data |
Definition at line 169 of file stream.cpp.
References acked_offset_, fin_acked_, fin_sent_, send_buffer_, send_offset_, and update_send_state().

|
nodiscardnoexcept |
Get available send window.
Definition at line 365 of file stream.cpp.
References max_send_offset_, send_buffer_, and send_offset_.
|
inlinenodiscardnoexcept |
Get bytes consumed from receive buffer.
Definition at line 347 of file stream.h.
References recv_offset_.
|
nodiscardnoexcept |
Check if stream can send data.
Definition at line 26 of file stream.cpp.
References is_local_, is_unidirectional(), kcenon::network::protocols::quic::ready, kcenon::network::protocols::quic::send, and send_state_.

|
inlinenodiscardnoexcept |
|
nodiscard |
Mark stream as finished (send FIN)
Definition at line 76 of file stream.cpp.
References kcenon::network::error_void(), kcenon::network::ok(), and kcenon::network::protocols::quic::stream_error::stream_state_error.

|
nodiscard |
Generate MAX_STREAM_DATA frame if needed.
Definition at line 391 of file stream.cpp.
|
nodiscardnoexcept |
Check if stream has data to read.
Definition at line 189 of file stream.cpp.
References recv_ready_.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Check if stream is bidirectional.
Definition at line 192 of file stream.h.
References id_, and kcenon::network::protocols::quic::stream_id_type::is_bidirectional().

|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Check if stream is unidirectional.
Definition at line 184 of file stream.h.
References id_, and kcenon::network::protocols::quic::stream_id_type::is_unidirectional().
Referenced by can_send().


|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
nodiscard |
Get next STREAM frame to send.
| max_size | Maximum frame size |
Definition at line 111 of file stream.cpp.
References kcenon::network::protocols::quic::stream_frame::stream_id.
|
delete |
|
defaultnoexcept |
|
inlinenodiscardnoexcept |
Get number of bytes pending to send.
Definition at line 239 of file stream.h.
References send_buffer_.
|
nodiscard |
Read data from stream.
| buffer | Buffer to read into |
Definition at line 194 of file stream.cpp.
References kcenon::network::protocols::quic::data_read, kcenon::network::protocols::quic::error, kcenon::network::ok(), kcenon::network::protocols::quic::reset_recvd, kcenon::network::protocols::quic::stream_error::stream_reset, and kcenon::network::protocols::quic::stream_error::stream_state_error.

|
private |
Definition at line 406 of file stream.cpp.
References recv_buffer_, recv_offset_, and recv_ready_.
|
nodiscard |
Receive STREAM frame data.
| offset | Data offset in stream |
| data | Frame data |
| fin | True if this is the final frame |
Definition at line 243 of file stream.cpp.
References kcenon::network::error_void(), kcenon::network::protocols::quic::stream_error::final_size_error, kcenon::network::protocols::quic::stream_error::flow_control_error, kcenon::network::ok(), kcenon::network::protocols::quic::reset_read, kcenon::network::protocols::quic::reset_recvd, and kcenon::network::protocols::quic::stream_error::stream_state_error.

|
nodiscard |
Handle received RESET_STREAM frame.
| error_code | Error code from peer |
| final_size | Final size of stream |
Definition at line 316 of file stream.cpp.
References kcenon::network::error_void(), kcenon::network::protocols::quic::stream_error::final_size_error, kcenon::network::ok(), kcenon::network::protocols::quic::reset_recvd, and kcenon::network::protocols::quic::stream_error::stream_state_error.

|
nodiscard |
Handle received STOP_SENDING frame.
| error_code | Error code from peer |
Definition at line 341 of file stream.cpp.
References kcenon::network::error_void(), kcenon::network::ok(), and kcenon::network::protocols::quic::stream_error::stream_state_error.

|
inlinenodiscardnoexcept |
|
nodiscard |
Reset the stream with error code.
| error_code | Application error code |
Definition at line 95 of file stream.cpp.
References kcenon::network::protocols::quic::data_recvd, kcenon::network::error_void(), kcenon::network::ok(), kcenon::network::protocols::quic::reset_recvd, kcenon::network::protocols::quic::reset_sent, and kcenon::network::protocols::quic::stream_error::stream_state_error.

|
inlinenodiscardnoexcept |
Get reset error code (if stream was reset)
Definition at line 367 of file stream.h.
References reset_error_code_.
|
inlinenodiscardnoexcept |
| void kcenon::network::protocols::quic::stream::set_max_recv_data | ( | uint64_t | max | ) |
Update our MAX_STREAM_DATA (peer's send limit)
| max | Maximum data peer can send |
Definition at line 374 of file stream.cpp.
References max_recv_offset_.
| void kcenon::network::protocols::quic::stream::set_max_send_data | ( | uint64_t | max | ) |
Set peer's MAX_STREAM_DATA (our send limit)
| max | Maximum data we can send |
Definition at line 358 of file stream.cpp.
References max_send_offset_.
|
nodiscardnoexcept |
Check if MAX_STREAM_DATA frame should be sent.
Definition at line 381 of file stream.cpp.
References max_recv_offset_, recv_offset_, recv_window_size_, and window_update_threshold_.
|
nodiscard |
Signal that incoming data is no longer wanted.
| error_code | Application error code |
Definition at line 231 of file stream.cpp.
References kcenon::network::error_void(), kcenon::network::ok(), and kcenon::network::protocols::quic::stream_error::stream_state_error.

|
inlinenodiscardnoexcept |
Get stop sending error code (if STOP_SENDING received)
Definition at line 375 of file stream.h.
References stop_sending_error_code_.
|
private |
Definition at line 452 of file stream.cpp.
References kcenon::network::protocols::quic::data_read, kcenon::network::protocols::quic::data_recvd, final_size_, kcenon::network::protocols::quic::recv, recv_fin_, recv_offset_, recv_ready_, recv_state_, kcenon::network::protocols::quic::reset_read, kcenon::network::protocols::quic::reset_recvd, and kcenon::network::protocols::quic::size_known.
|
private |
Definition at line 420 of file stream.cpp.
References kcenon::network::protocols::quic::data_recvd, kcenon::network::protocols::quic::data_sent, fin_acked_, fin_sent_, kcenon::network::protocols::quic::ready, kcenon::network::protocols::quic::reset_recvd, kcenon::network::protocols::quic::reset_sent, kcenon::network::protocols::quic::send, send_buffer_, and send_state_.
Referenced by acknowledge_data().

|
nodiscard |
Write data to stream.
| data | Data to write |
Definition at line 42 of file stream.cpp.
References kcenon::network::protocols::quic::error, kcenon::network::protocols::quic::stream_error::flow_control_error, kcenon::network::ok(), kcenon::network::protocols::quic::ready, kcenon::network::protocols::quic::send, and kcenon::network::protocols::quic::stream_error::stream_state_error.

|
private |
Definition at line 388 of file stream.h.
Referenced by acknowledge_data().
|
private |
Definition at line 390 of file stream.h.
Referenced by acknowledge_data(), and update_send_state().
|
private |
Definition at line 389 of file stream.h.
Referenced by acknowledge_data(), fin_sent(), and update_send_state().
|
private |
Definition at line 398 of file stream.h.
Referenced by update_recv_state().
|
private |
Definition at line 381 of file stream.h.
Referenced by id(), is_bidirectional(), and is_unidirectional().
|
private |
Definition at line 382 of file stream.h.
Referenced by can_send(), and is_local().
|
private |
Definition at line 404 of file stream.h.
Referenced by max_recv_data(), set_max_recv_data(), and should_send_max_stream_data().
|
private |
Definition at line 401 of file stream.h.
Referenced by available_send_window(), max_send_data(), and set_max_send_data().
|
private |
Definition at line 394 of file stream.h.
Referenced by reassemble_data().
|
private |
Definition at line 397 of file stream.h.
Referenced by is_fin_received(), and update_recv_state().
|
private |
Definition at line 396 of file stream.h.
Referenced by bytes_consumed(), reassemble_data(), should_send_max_stream_data(), and update_recv_state().
|
private |
Definition at line 395 of file stream.h.
Referenced by has_data(), reassemble_data(), and update_recv_state().
|
private |
Definition at line 393 of file stream.h.
Referenced by recv_state(), and update_recv_state().
|
private |
|
private |
Definition at line 409 of file stream.h.
Referenced by reset_error_code().
|
private |
Definition at line 386 of file stream.h.
Referenced by acknowledge_data(), available_send_window(), pending_bytes(), and update_send_state().
|
private |
Definition at line 387 of file stream.h.
Referenced by acknowledge_data(), and available_send_window().
|
private |
Definition at line 385 of file stream.h.
Referenced by can_send(), send_state(), and update_send_state().
|
private |
Definition at line 410 of file stream.h.
Referenced by stop_sending_error_code().
|
staticconstexprprivate |