34namespace stream_id_type
46 return (stream_id & 0x01) == 0;
54 return (stream_id & 0x01) == 1;
62 return (stream_id & 0x02) == 0;
70 return (stream_id & 0x02) != 0;
76 [[nodiscard]]
constexpr auto get_type(uint64_t stream_id)
noexcept -> uint64_t
78 return stream_id & 0x03;
84 [[nodiscard]]
constexpr auto get_sequence(uint64_t stream_id)
noexcept -> uint64_t
86 return stream_id >> 2;
92 [[nodiscard]]
constexpr auto make_stream_id(uint64_t type, uint64_t sequence)
noexcept -> uint64_t
94 return (sequence << 2) | (type & 0x03);
127namespace stream_error
155 explicit stream(uint64_t
id,
bool is_local, uint64_t initial_max_data = 65536);
174 [[nodiscard]] auto
id() const noexcept -> uint64_t {
return id_; }
209 [[nodiscard]]
auto can_send() const noexcept ->
bool;
216 [[nodiscard]] auto
write(std::span<const uint8_t> data) ->
Result<
size_t>;
246 [[nodiscard]]
auto next_stream_frame(
size_t max_size) -> std::optional<stream_frame>;
267 [[nodiscard]]
auto has_data() const noexcept ->
bool;
274 [[nodiscard]] auto
read(std::span<uint8_t> buffer) ->
Result<
size_t>;
295 [[nodiscard]]
auto receive_data(uint64_t offset, std::span<const uint8_t> data,
bool fin)
QUIC stream implementation (RFC 9000 Sections 2-4)
auto should_send_max_stream_data() const noexcept -> bool
Check if MAX_STREAM_DATA frame should be sent.
auto finish() -> VoidResult
Mark stream as finished (send FIN)
std::optional< uint64_t > final_size_
auto stop_sending_error_code() const noexcept -> std::optional< uint64_t >
Get stop sending error code (if STOP_SENDING received)
auto send_state() const noexcept -> send_stream_state
Get send state.
auto generate_max_stream_data() -> std::optional< uint64_t >
Generate MAX_STREAM_DATA frame if needed.
auto receive_reset(uint64_t error_code, uint64_t final_size) -> VoidResult
Handle received RESET_STREAM frame.
stream(stream &&) noexcept=default
uint64_t max_recv_offset_
auto is_local() const noexcept -> bool
Check if stream is locally initiated.
void set_max_recv_data(uint64_t max)
Update our MAX_STREAM_DATA (peer's send limit)
auto is_unidirectional() const noexcept -> bool
Check if stream is unidirectional.
auto is_fin_received() const noexcept -> bool
Check if all data has been received.
std::map< uint64_t, std::vector< uint8_t > > recv_buffer_
auto receive_data(uint64_t offset, std::span< const uint8_t > data, bool fin) -> VoidResult
Receive STREAM frame data.
auto has_data() const noexcept -> bool
Check if stream has data to read.
auto can_send() const noexcept -> bool
Check if stream can send data.
stream(uint64_t id, bool is_local, uint64_t initial_max_data=65536)
Construct a stream.
auto max_send_data() const noexcept -> uint64_t
Get peer's MAX_STREAM_DATA.
auto write(std::span< const uint8_t > data) -> Result< size_t >
Write data to stream.
void set_max_send_data(uint64_t max)
Set peer's MAX_STREAM_DATA (our send limit)
auto reset(uint64_t error_code) -> VoidResult
Reset the stream with error code.
auto available_send_window() const noexcept -> size_t
Get available send window.
auto recv_state() const noexcept -> recv_stream_state
Get receive state.
uint64_t max_send_offset_
std::optional< uint64_t > stop_sending_error_code_
std::deque< uint8_t > recv_ready_
recv_stream_state recv_state_
auto operator=(const stream &) -> stream &=delete
auto reset_error_code() const noexcept -> std::optional< uint64_t >
Get reset error code (if stream was reset)
void acknowledge_data(uint64_t offset, uint64_t length)
Acknowledge sent data.
auto max_recv_data() const noexcept -> uint64_t
Get our MAX_STREAM_DATA.
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.
std::deque< uint8_t > send_buffer_
static constexpr double window_update_threshold_
auto bytes_consumed() const noexcept -> uint64_t
Get bytes consumed from receive buffer.
send_stream_state send_state_
std::optional< uint64_t > reset_error_code_
uint64_t recv_window_size_
auto is_bidirectional() const noexcept -> bool
Check if stream is bidirectional.
auto next_stream_frame(size_t max_size) -> std::optional< stream_frame >
Get next STREAM frame to send.
stream(const stream &)=delete
auto receive_stop_sending(uint64_t error_code) -> VoidResult
Handle received STOP_SENDING frame.
auto read(std::span< uint8_t > buffer) -> Result< size_t >
Read data from stream.
constexpr int stream_reset
constexpr int flow_control_error
constexpr int final_size_error
constexpr int stream_limit_exceeded
constexpr int invalid_stream_id
constexpr int stream_state_error
constexpr int buffer_full
constexpr int stream_not_found
constexpr uint64_t client_uni
constexpr auto is_unidirectional(uint64_t stream_id) noexcept -> bool
Check if stream is unidirectional.
constexpr auto is_server_initiated(uint64_t stream_id) noexcept -> bool
Check if stream is server-initiated.
constexpr uint64_t server_uni
constexpr auto is_bidirectional(uint64_t stream_id) noexcept -> bool
Check if stream is bidirectional.
constexpr auto is_client_initiated(uint64_t stream_id) noexcept -> bool
Check if stream is client-initiated.
constexpr auto get_type(uint64_t stream_id) noexcept -> uint64_t
Get stream type bits (0-3)
constexpr uint64_t client_bidi
constexpr uint64_t server_bidi
constexpr auto make_stream_id(uint64_t type, uint64_t sequence) noexcept -> uint64_t
Make stream ID from type and sequence number.
constexpr auto get_sequence(uint64_t stream_id) noexcept -> uint64_t
Get stream sequence number (stream_id >> 2)
auto recv_state_to_string(recv_stream_state state) -> const char *
Get string representation of receive stream state.
recv_stream_state
Stream state for receiving (RFC 9000 Section 3.2)
@ size_known
FIN received, final size known.
@ data_read
All data read by application (terminal)
@ reset_read
Reset acknowledged by application (terminal)
auto send_state_to_string(send_stream_state state) -> const char *
Get string representation of send stream state.
send_stream_state
Stream state for sending (RFC 9000 Section 3.1)
@ reset_sent
RESET_STREAM sent.
@ reset_recvd
Reset acknowledged by peer (terminal)
@ data_recvd
All data acknowledged (terminal)
@ ready
Stream is ready, can send data.
@ data_sent
All data sent, awaiting ACKs.
Result< std::monostate > VoidResult
Network-specific error and result type definitions.