Skip to main content

Connection

Struct Connection 

Source
pub struct Connection<Io> { /* private fields */ }
Available on crate feature h2 only.
Expand description

An HTTP/2 server connection.

Io must be a raw transport: the preface is read byte-exact, so any buffering layer between the socket and this type breaks the initial read.

Implementations§

Source§

impl<Io> Connection<Io>
where Io: AsyncRead + AsyncWrite + Unpin,

Source

pub fn new(io: Io, preface_timeout: Option<Duration>) -> Connection<Io>

Creates a connection over io.

Source

pub fn with_shutdown(self, token: CancellationToken) -> Self

Arms a CancellationToken that triggers a graceful shutdown when cancelled: the connection sends GOAWAY, stops opening new streams, drains in-flight responses, then closes (RFC 9113 Section 6.8).

Source

pub async fn drive(self) -> Result<()>

Drives a connection that never serves requests: the preface handshake, SETTINGS/PING maintenance and error handling, but no request dispatch (any request stream is refused).

Equivalent to Connection::handle with a handler that never completes; kept for tests and for callers that only want the connection-level behavior.

Source

pub async fn handle<F, Fut, ResB, ResBE, ResE>( self, request_fn: Arc<F>, options: ConnectionOptions, ) -> Result<()>
where F: Fn(Request<Incoming>) -> Fut + 'static, Fut: Future<Output = Result<Response<ResB>, ResE>> + 'static, ResB: Body<Data = Bytes, Error = ResBE> + Unpin + 'static, ResBE: Error + 'static, ResE: Error + 'static,

Serves requests to completion: peer EOF, GOAWAY received, preface timeout, or an unrecoverable protocol error.

Each decoded request starts a stream task running request_fn (a clone-free sequential borrow: the loop owns the closure for the connection’s lifetime). Responses are framed onto the wire by this task as the stream tasks emit them.

Auto Trait Implementations§

§

impl<Io> !RefUnwindSafe for Connection<Io>

§

impl<Io> !UnwindSafe for Connection<Io>

§

impl<Io> Freeze for Connection<Io>
where Io: Freeze,

§

impl<Io> Send for Connection<Io>
where Io: Send,

§

impl<Io> Sync for Connection<Io>
where Io: Sync,

§

impl<Io> Unpin for Connection<Io>
where Io: Unpin,

§

impl<Io> UnsafeUnpin for Connection<Io>
where Io: UnsafeUnpin,

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.