pub struct Connection { /* private fields */ }Expand description
HTTP/2 connection state machine (sans-io).
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn new(role: Role, cfg: ConnectionConfig) -> Self
pub fn new(role: Role, cfg: ConnectionConfig) -> Self
New connection. Emits the client preface + initial SETTINGS (client role) or the server’s initial SETTINGS (server role) into the pending-write buffer.
Sourcepub fn take_pending_writes(&mut self) -> Vec<u8> ⓘ
pub fn take_pending_writes(&mut self) -> Vec<u8> ⓘ
Bytes the driver must flush to the peer.
Sourcepub fn connection_error(&self) -> Option<ConnectionError>
pub fn connection_error(&self) -> Option<ConnectionError>
Connection error, if any. The driver sends the GOAWAY (already queued in pending writes) and closes.
Sourcepub fn peer_max_frame_size(&self) -> usize
pub fn peer_max_frame_size(&self) -> usize
The peer’s SETTINGS_MAX_FRAME_SIZE (largest frame payload we may send).
Sourcepub fn send_budget(&self, stream_id: u32) -> usize
pub fn send_budget(&self, stream_id: u32) -> usize
Available send credit for stream_id (min of stream and
connection windows, clamped at zero).
Sourcepub fn stream_is_open(&self, stream_id: u32) -> bool
pub fn stream_is_open(&self, stream_id: u32) -> bool
Whether the stream is currently tracked (open or half-closed).
Sourcepub fn conn_send_window_probe(&self) -> i64
pub fn conn_send_window_probe(&self) -> i64
Debug: connection send window.
Sourcepub fn stream_send_window_probe(&self, stream_id: u32) -> i64
pub fn stream_send_window_probe(&self, stream_id: u32) -> i64
Debug: stream send window.
Sourcepub fn debug_send_windows(&self, stream_id: u32) -> (i64, i64)
pub fn debug_send_windows(&self, stream_id: u32) -> (i64, i64)
Debug: current send windows (conn, stream if open).
Sourcepub fn grant_send_for_test(&mut self, stream_id: u32, n: u32)
pub fn grant_send_for_test(&mut self, stream_id: u32, n: u32)
Test-only: grants n bytes of send credit (simulates a peer
WINDOW_UPDATE on stream + connection without a frame round-trip).
Sourcepub fn consume_send_budget(&mut self, stream_id: u32, n: usize) -> usize
pub fn consume_send_budget(&mut self, stream_id: u32, n: usize) -> usize
Reserves n bytes of send credit for DATA the driver emits
directly (frame bytes assembled outside the engine). The engine
never sees those frames through Self::send_data, so the
stream and connection windows must be debited here; peer
WINDOW_UPDATEs replenish via Self::handle_read.
Returns the amount actually reserved (≤ n).
Sourcepub fn peer_goaway(&self) -> Option<(u32, u32)>
pub fn peer_goaway(&self) -> Option<(u32, u32)>
Whether the peer sent GOAWAY.
Sourcepub fn handle_read(&mut self, data: &[u8], events: &mut Vec<Event>) -> usize
pub fn handle_read(&mut self, data: &[u8], events: &mut Vec<Event>) -> usize
Feeds inbound peer bytes into the state machine. Emits events and queues outbound frames (ACKs, WINDOW_UPDATEs, GOAWAY, RSTs). Returns the number of bytes consumed by fully-processed frames; a trailing partial frame is left unconsumed so drivers can buffer the remainder.
Sourcepub fn release_capacity(&mut self, stream_id: u32, n: usize)
pub fn release_capacity(&mut self, stream_id: u32, n: usize)
Credits the peer for consumed body bytes (emits WINDOW_UPDATEs on connection + stream when the freed amount is significant).
Sourcepub fn open_stream(&mut self, stream_id: u32)
pub fn open_stream(&mut self, stream_id: u32)
Opens a new outbound stream (client role) or validates the id for a server-initiated response path.
Sourcepub fn alloc_stream_id(&mut self) -> u32
pub fn alloc_stream_id(&mut self) -> u32
Allocates the next outbound stream id.
Sourcepub fn send_headers(
&mut self,
stream_id: u32,
headers: &[(Vec<u8>, Vec<u8>)],
end_stream: bool,
)
pub fn send_headers( &mut self, stream_id: u32, headers: &[(Vec<u8>, Vec<u8>)], end_stream: bool, )
Sends a response/request HEADERS block (HPACK-encoded, split into
CONTINUATIONs by the peer’s max frame size). end_stream closes
the send side.
Sourcepub fn send_data(
&mut self,
stream_id: u32,
data: &[u8],
end_stream: bool,
) -> usize
pub fn send_data( &mut self, stream_id: u32, data: &[u8], end_stream: bool, ) -> usize
Sends DATA on a stream, capped by connection + stream send windows and the peer’s max frame size. Returns bytes sent (remainder awaits WINDOW_UPDATE credit).
Sourcepub fn send_rst_stream(&mut self, stream_id: u32, code: u32)
pub fn send_rst_stream(&mut self, stream_id: u32, code: u32)
Sends RST_STREAM to close a stream with an error.
Sourcepub fn send_goaway(&mut self, error_code: u32)
pub fn send_goaway(&mut self, error_code: u32)
Sends GOAWAY (draining).