H3Session struct final
#include <src/microserve/http3_conn.cppm>
HTTP/3 session on top of one QUIC connection.
Owns nghttp3 plus per-stream request/response state. Never touches UDP, CIDs, or SSL_CTX.
Base classes
- struct QuicApp
- Application sitting on a QUIC connection (HTTP/3 session).
Public types
- struct BufferedStreamData
- STREAM data received before nghttp3 is ready, replayed after handshake.
Constructors, destructors, conversion operators
- H3Session(QuicTransport& qt, Handler* handler)
- Bind this session to
qtand the shared requesthandler. - ~H3Session() override
- Release response bodies and destroy the nghttp3 connection.
Public functions
- auto on_handshake_completed() -> int override
- Handshake completed; initialise HTTP/3.
- auto on_recv_stream_data(int64_t stream_id, const uint8_t* data, size_t data_len, int fin, size_t& consumed) -> int override
- Feed STREAM data into nghttp3, or buffer it until HTTP/3 is ready.
- auto on_stream_open(int64_t stream_id) -> int override
- Record a newly opened stream.
- auto on_stream_close(int64_t stream_id, uint64_t app_error_code, bool app_error_set, bool bidi) -> int override
- Close
stream_idin nghttp3 and drop local state. - auto on_acked_stream_data(int64_t stream_id, uint64_t data_len) -> int override
- Notify nghttp3 that previously sent STREAM data was acknowledged.
- void on_extend_max_remote_streams_bidi(uint64_t max_streams) override
- Forward a new bidirectional remote-stream limit to nghttp3.
- auto on_extend_max_stream_data(int64_t stream_id) -> int override
- Unblock
stream_idin nghttp3 after its send window grew. - void on_stream_reset(int64_t stream_id) override
- Stop reading
stream_idand drop local state after a reset. - auto poll_stream_write(int64_t& stream_id, int& fin, QuicVec* vecs, size_t size) -> int override
- Fill
vecswith the next nghttp3 STREAM write, if any. - auto add_write_offset(int64_t stream_id, size_t n) -> int override
- Advance nghttp3's write offset after
nbytes were sent. - void block_stream(int64_t stream_id) override
- Mark
stream_idblocked on flow control in nghttp3. - void shutdown_stream_write(int64_t stream_id) override
- Stop sending on
stream_id(half-close the write side). - auto init_http3() -> int
- Create the nghttp3 server connection and bind control / QPACK streams.
- void on_h3_request(int64_t stream_id)
- Dispatch a completed request on
stream_idto the handler. - void submit_response(int64_t stream_id, const Response& res)
- Submit
resonstream_idvia nghttp3. - auto verbosity() const -> int
- Current log verbosity (
0is quiet). - void error(const std::string& m) const
- Log an error message via the transport.
- void info(const std::string& m) const
- Log an info message via the transport.
- void debug(const std::string& m) const
- Log a debug message via the transport.
Public variables
- QuicTransport& qt
- Transport used to open streams and log.
- Handler* handler
- Shared request handler (non-owning).
- nghttp3_conn* h3
- nghttp3 connection, created after handshake.
- std::map<int64_t, StreamState> streams
- Client-initiated request streams.
- std::map<int64_t, std::unique_ptr<BodyHolder>> bodies
- Response bodies still being written.
- bool h3_ready
trueafter control / QPACK streams are bound.- std::vector<BufferedStreamData> pending_stream_data
- Replay queue until init_
http3.
Function documentation
int microserve:: http3_detail:: H3Session:: on_handshake_completed() override
Handshake completed; initialise HTTP/3.
| Returns | 0 on success, -1 on failure. |
|---|
int microserve:: http3_detail:: H3Session:: on_recv_stream_data(int64_t stream_id,
const uint8_t* data,
size_t data_len,
int fin,
size_t& consumed) override
Feed STREAM data into nghttp3, or buffer it until HTTP/3 is ready.
| Parameters | |
|---|---|
| stream_id | Stream that received data. |
| data | Payload bytes. |
| data_len | Payload length. |
| fin | Non-zero if this is the final STREAM chunk. |
| consumed | Set to the number of bytes accepted from data. |
| Returns | 0 on success, -1 on failure. |
int microserve:: http3_detail:: H3Session:: on_stream_open(int64_t stream_id) override
Record a newly opened stream.
| Parameters | |
|---|---|
| stream_id | Newly opened stream. |
| Returns | 0. |
int microserve:: http3_detail:: H3Session:: on_stream_close(int64_t stream_id,
uint64_t app_error_code,
bool app_error_set,
bool bidi) override
Close stream_id in nghttp3 and drop local state.
| Parameters | |
|---|---|
| stream_id | Closed stream. |
| app_error_code | Application error code, if set. |
| app_error_set | true when app_error_code is valid. |
| bidi | true for a bidirectional stream. |
| Returns | 0 on success, -1 on failure. |
int microserve:: http3_detail:: H3Session:: on_acked_stream_data(int64_t stream_id,
uint64_t data_len) override
Notify nghttp3 that previously sent STREAM data was acknowledged.
| Parameters | |
|---|---|
| stream_id | Stream whose data was ACKed. |
| data_len | Number of acknowledged bytes. |
| Returns | 0 on success, -1 on failure. |
void microserve:: http3_detail:: H3Session:: on_extend_max_remote_streams_bidi(uint64_t max_streams) override
Forward a new bidirectional remote-stream limit to nghttp3.
| Parameters | |
|---|---|
| max_streams | New maximum number of remote bidi streams. |
int microserve:: http3_detail:: H3Session:: on_extend_max_stream_data(int64_t stream_id) override
Unblock stream_id in nghttp3 after its send window grew.
| Parameters | |
|---|---|
| stream_id | Stream whose send window grew. |
| Returns | 0 on success, -1 on failure. |
void microserve:: http3_detail:: H3Session:: on_stream_reset(int64_t stream_id) override
Stop reading stream_id and drop local state after a reset.
| Parameters | |
|---|---|
| stream_id | Reset stream. |
int microserve:: http3_detail:: H3Session:: poll_stream_write(int64_t& stream_id,
int& fin,
QuicVec* vecs,
size_t size) override
Fill vecs with the next nghttp3 STREAM write, if any.
| Parameters | |
|---|---|
| stream_id | Set to the stream that should be written. |
| fin | Set to non-zero if this is the last chunk. |
| vecs | Output scatter list. |
| size | Capacity of vecs. |
| Returns | Number of vectors filled, 0 if nothing to send, or -1 on error. |
int microserve:: http3_detail:: H3Session:: add_write_offset(int64_t stream_id,
size_t n) override
Advance nghttp3's write offset after n bytes were sent.
| Parameters | |
|---|---|
| stream_id | Stream that was written. |
| n | Bytes just sent. |
| Returns | 0 on success, -1 on failure. |
void microserve:: http3_detail:: H3Session:: block_stream(int64_t stream_id) override
Mark stream_id blocked on flow control in nghttp3.
| Parameters | |
|---|---|
| stream_id | Stream that cannot send until the window grows. |
void microserve:: http3_detail:: H3Session:: shutdown_stream_write(int64_t stream_id) override
Stop sending on stream_id (half-close the write side).
| Parameters | |
|---|---|
| stream_id | Stream whose write side is shut down. |
int microserve:: http3_detail:: H3Session:: init_http3()
Create the nghttp3 server connection and bind control / QPACK streams.
| Returns | 0 on success, -1 on failure. |
|---|
Replays any STREAM data buffered before the handshake completed.
void microserve:: http3_detail:: H3Session:: on_h3_request(int64_t stream_id)
Dispatch a completed request on stream_id to the handler.
| Parameters | |
|---|---|
| stream_id | Client-initiated stream whose headers (and body) are complete. |
void microserve:: http3_detail:: H3Session:: submit_response(int64_t stream_id,
const Response& res)
Submit res on stream_id via nghttp3.
| Parameters | |
|---|---|
| stream_id | Stream to respond on. |
| res | Application response (status, headers, body). |
int microserve:: http3_detail:: H3Session:: verbosity() const
Current log verbosity (0 is quiet).
| Returns | Verbosity level from the owning transport. |
|---|
void microserve:: http3_detail:: H3Session:: error(const std::string& m) const
Log an error message via the transport.
| Parameters | |
|---|---|
| m | Message to log. |
void microserve:: http3_detail:: H3Session:: info(const std::string& m) const
Log an info message via the transport.
| Parameters | |
|---|---|
| m | Message to log. |
void microserve:: http3_detail:: H3Session:: debug(const std::string& m) const
Log a debug message via the transport.
| Parameters | |
|---|---|
| m | Message to log. |