pub struct H2Connection { /* private fields */ }Expand description
Implementations§
Source§impl H2Connection
impl H2Connection
Sourcepub fn send_ping(&self, opaque: [u8; 8]) -> SendPing<'_>
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
impl H2Connection
Sourcepub fn new(context: Arc<HttpContext>) -> Arc<Self>
pub fn new(context: Arc<HttpContext>) -> Arc<Self>
Construct a new H2Connection to manage HTTP/2 for a single peer.
Sourcepub fn context(&self) -> Arc<HttpContext>
pub fn context(&self) -> Arc<HttpContext>
The HttpContext this connection was constructed with.
Sourcepub fn swansong(&self) -> &Swansong
pub fn swansong(&self) -> &Swansong
The connection-scoped Swansong. Shuts down on peer GOAWAY or when the server-
level swansong shuts down.
Sourcepub fn shut_down(&self) -> ShutdownCompletion
pub fn shut_down(&self) -> ShutdownCompletion
Attempt graceful shutdown of this HTTP/2 connection.
Sourcepub fn run<T>(self: Arc<Self>, transport: T) -> H2Driver<T>
pub fn run<T>(self: Arc<Self>, transport: T) -> H2Driver<T>
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.
Sourcepub async fn process_inbound<Transport, Handler, Fut>(
conn: Conn<Transport>,
handler: Handler,
) -> Result<Conn<Transport>>
pub async fn process_inbound<Transport, Handler, Fut>( conn: Conn<Transport>, handler: Handler, ) -> Result<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.