Skip to main content

H2Connection

Struct H2Connection 

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

Shared per-connection state for HTTP/2.

Wrapped in an Arc and held by both the H2Driver driver and every conn task that holds an open stream’s Conn. Per-stream StreamState, HPACK encoder state, and connection-level send flow control lives here.

Implementations§

Source§

impl H2Connection

Source

pub fn send_ping(&self, opaque: [u8; 8]) -> SendPing<'_>

Send a PING frame to the peer and resolve when its PING ACK arrives, returning the round-trip time.

opaque is the 8-byte payload echoed back by the peer (RFC 9113 §6.7). Caller picks the value — typically a counter or a random nonce. A PING whose opaque payload is already in flight on this connection resolves to io::ErrorKind::AlreadyExists.

No internal timeout. Wrap the returned future with the runtime’s race_with_timeout (or equivalent) to bound the wait.

§Cancel safety

Dropping the returned future before completion removes the pending entry from this connection’s tracking map. The PING frame may still go out (or already have gone out) and the peer’s ACK is silently dropped. Re-using the same opaque after drop is safe.

§Panics

Panics if any of the per-connection mutexes is poisoned (a previous thread panicked while holding the lock) — same posture as the rest of the h2 driver’s mutex usage.

Source§

impl H2Connection

Source

pub fn new(context: Arc<HttpContext>) -> Arc<Self>

Construct a new H2Connection to manage HTTP/2 for a single peer.

Source

pub fn context(&self) -> Arc<HttpContext>

The HttpContext this connection was constructed with.

Source

pub fn swansong(&self) -> &Swansong

The connection-scoped Swansong. Shuts down on peer GOAWAY or when the server- level swansong shuts down.

Source

pub fn shut_down(&self) -> ShutdownCompletion

Attempt graceful shutdown of this HTTP/2 connection.

Source

pub fn run<T>(self: Arc<Self>, transport: T) -> H2Driver<T>
where T: AsyncRead + AsyncWrite + Unpin + Send,

Bind this H2Connection to a TCP transport and return an H2Driver that drives the connection.

The driver must be polled to completion via repeated calls to H2Driver::next (or its Stream impl); each returned Conn should be spawned on its own task.

Source

pub async fn process_inbound<Transport, Handler, Fut>( conn: Conn<Transport>, handler: Handler, ) -> Result<Conn<Transport>>
where Transport: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static, Handler: FnOnce(Conn<Transport>) -> Fut, Fut: Future<Output = Conn<Transport>>,

Per-stream entry point — call from the runtime adapter’s spawned task for each Conn returned by H2Driver::next. Runs handler to produce the response, then send_h2 to hand the framed response to the driver.

Mirrors H3Connection::process_inbound_bidi’s role for h3, except the Conn is already built (the acceptor decoded HEADERS and validated the request before emitting), so this just runs the handler chain and sends.

§Errors

Returns the io::Error from send_h2 if the body’s poll_read errors or the underlying transport fails partway through the response.

Trait Implementations§

Source§

impl Debug for H2Connection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.