Struct Connection

struct Connection<T, B: Buf = bytes::Bytes> { ... }

Manages all state associated with an HTTP/2 client connection.

A Connection is backed by an I/O resource (usually a TCP socket) and implements the HTTP/2 client logic for that connection. It is responsible for driving the internal state forward, performing the work requested of the associated handles (SendRequest, ResponseFuture, SendStream, RecvStream).

Connection values are created by calling handshake. Once a Connection value is obtained, the caller must repeatedly call poll until Ready is returned. The easiest way to do this is to submit the Connection instance to an executor.

Examples

# use tokio::io::{AsyncRead, AsyncWrite};
# use h2::client;
# use h2::client::*;
#
# async fn doc<T>(my_io: T) -> Result<(), h2::Error>
# where T: AsyncRead + AsyncWrite + Send + Unpin + 'static,
# {
    let (send_request, connection) = client::handshake(my_io).await?;
    // Submit the connection handle to an executor.
    tokio::spawn(async { connection.await.expect("connection failed"); });

    // Now, use `send_request` to initialize HTTP/2 streams.
    // ...
# Ok(())
# }
#
# pub fn main() {}

Implementations

impl<T, B> Connection<T, B>

fn set_target_window_size(self: &mut Self, size: u32)

Sets the target window size for the whole connection.

If size is greater than the current value, then a WINDOW_UPDATE frame will be immediately sent to the remote, increasing the connection level window by size - current_value.

If size is less than the current value, nothing will happen immediately. However, as window capacity is released by FlowControl instances, no WINDOW_UPDATE frames will be sent out until the number of "in flight" bytes drops below size.

The default value is 65,535.

See FlowControl documentation for more details.

fn set_initial_window_size(self: &mut Self, size: u32) -> Result<(), Error>

Set a new INITIAL_WINDOW_SIZE setting (in octets) for stream-level flow control for received data.

The SETTINGS will be sent to the remote, and only applied once the remote acknowledges the change.

This can be used to increase or decrease the window size for existing streams.

Errors

Returns an error if a previous call is still pending acknowledgement from the remote endpoint.

fn ping_pong(self: &mut Self) -> Option<PingPong>

Takes a PingPong instance from the connection.

Note

This may only be called once. Calling multiple times will return None.

fn max_concurrent_send_streams(self: &Self) -> usize

Returns the maximum number of concurrent streams that may be initiated by this client.

This limit is configured by the server peer by sending the SETTINGS_MAX_CONCURRENT_STREAMS parameter in a SETTINGS frame. This method returns the currently acknowledged value received from the remote.

fn max_concurrent_recv_streams(self: &Self) -> usize

Returns the maximum number of concurrent streams that may be initiated by the server on this connection.

This returns the value of the SETTINGS_MAX_CONCURRENT_STREAMS parameter sent in a SETTINGS frame that has been acknowledged by the remote peer. The value to be sent is configured by the Builder::max_concurrent_streams method before handshaking with the remote peer.

impl<F> IntoFuture for Connection<T, B>

fn into_future(self: Self) -> <F as IntoFuture>::IntoFuture

impl<F, T, E> TryFuture for Connection<T, B>

fn try_poll(self: Pin<&mut F>, cx: &mut Context<'_>) -> Poll<<F as Future>::Output>

impl<T> Any for Connection<T, B>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Connection<T, B>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Connection<T, B>

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

impl<T> From for Connection<T, B>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Connection<T, B>

impl<T> WithSubscriber for Connection<T, B>

impl<T, B = Bytes> Freeze for Connection<T, B>

impl<T, B = Bytes> RefUnwindSafe for Connection<T, B>

impl<T, B = Bytes> UnwindSafe for Connection<T, B>

impl<T, B> Debug for Connection<T, B>

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

impl<T, B> Future for Connection<T, B>

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<<Self as >::Output>

impl<T, B> Send for Connection<T, B>

impl<T, B> Sync for Connection<T, B>

impl<T, B> Unpin for Connection<T, B>

impl<T, B> UnsafeUnpin for Connection<T, B>

impl<T, U> Into for Connection<T, B>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for Connection<T, B>

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

impl<T, U> TryInto for Connection<T, B>

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