Skip to main content

Connection

Struct Connection 

Source
pub struct Connection { /* private fields */ }
Expand description

HTTP/2 connection state machine (sans-io).

Implementations§

Source§

impl Connection

Source

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.

Source

pub fn take_pending_writes(&mut self) -> Vec<u8> ⓘ

Bytes the driver must flush to the peer.

Source

pub fn connection_error(&self) -> Option<ConnectionError>

Connection error, if any. The driver sends the GOAWAY (already queued in pending writes) and closes.

Source

pub fn peer_max_frame_size(&self) -> usize

The peer’s SETTINGS_MAX_FRAME_SIZE (largest frame payload we may send).

Source

pub fn send_budget(&self, stream_id: u32) -> usize

Available send credit for stream_id (min of stream and connection windows, clamped at zero).

Source

pub fn stream_is_open(&self, stream_id: u32) -> bool

Whether the stream is currently tracked (open or half-closed).

Source

pub fn conn_send_window_probe(&self) -> i64

Debug: connection send window.

Source

pub fn stream_send_window_probe(&self, stream_id: u32) -> i64

Debug: stream send window.

Source

pub fn debug_send_windows(&self, stream_id: u32) -> (i64, i64)

Debug: current send windows (conn, stream if open).

Source

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).

Source

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).

Source

pub fn peer_goaway(&self) -> Option<(u32, u32)>

Whether the peer sent GOAWAY.

Source

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.

Source

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).

Source

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.

Source

pub fn alloc_stream_id(&mut self) -> u32

Allocates the next outbound stream id.

Source

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.

Source

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).

Source

pub fn send_rst_stream(&mut self, stream_id: u32, code: u32)

Sends RST_STREAM to close a stream with an error.

Source

pub fn send_ping(&mut self, payload: &[u8; 8])

Sends a PING with an opaque 8-byte payload.

Source

pub fn send_goaway(&mut self, error_code: u32)

Sends GOAWAY (draining).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V