Struct h2::client::Connection
source · pub struct Connection<T, B: Buf = Bytes> { /* private fields */ }
Expand description
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
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.
// ...
Implementations§
source§impl<T, B> Connection<T, B>where
T: AsyncRead + AsyncWrite + Unpin,
B: Buf,
impl<T, B> Connection<T, B>where T: AsyncRead + AsyncWrite + Unpin, B: Buf,
sourcepub fn set_target_window_size(&mut self, size: u32)
pub fn set_target_window_size(&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.
sourcepub fn set_initial_window_size(&mut self, size: u32) -> Result<(), Error>
pub fn set_initial_window_size(&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.
sourcepub fn ping_pong(&mut self) -> Option<PingPong>
pub fn ping_pong(&mut self) -> Option<PingPong>
Takes a PingPong
instance from the connection.
Note
This may only be called once. Calling multiple times will return None
.
sourcepub fn max_concurrent_send_streams(&self) -> usize
pub fn max_concurrent_send_streams(&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.
sourcepub fn max_concurrent_recv_streams(&self) -> usize
pub fn max_concurrent_recv_streams(&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.
Trait Implementations§
source§impl<T, B> Debug for Connection<T, B>where
T: AsyncRead + AsyncWrite + Debug,
B: Debug + Buf,
impl<T, B> Debug for Connection<T, B>where T: AsyncRead + AsyncWrite + Debug, B: Debug + Buf,
source§impl<T, B> Future for Connection<T, B>where
T: AsyncRead + AsyncWrite + Unpin,
B: Buf,
impl<T, B> Future for Connection<T, B>where T: AsyncRead + AsyncWrite + Unpin, B: Buf,
Auto Trait Implementations§
impl<T, B = Bytes> !RefUnwindSafe for Connection<T, B>
impl<T, B> Send for Connection<T, B>where B: Send, T: Send,
impl<T, B> Sync for Connection<T, B>where B: Send + Sync, T: Sync,
impl<T, B> Unpin for Connection<T, B>where T: Unpin,
impl<T, B = Bytes> !UnwindSafe for Connection<T, B>
Blanket Implementations§
source§impl<T> FutureExt for Twhere
T: Future + ?Sized,
impl<T> FutureExt for Twhere T: Future + ?Sized,
source§fn map<U, F>(self, f: F) -> Map<Self, F>where
F: FnOnce(Self::Output) -> U,
Self: Sized,
fn map<U, F>(self, f: F) -> Map<Self, F>where F: FnOnce(Self::Output) -> U, Self: Sized,
source§fn map_into<U>(self) -> MapInto<Self, U>where
Self::Output: Into<U>,
Self: Sized,
fn map_into<U>(self) -> MapInto<Self, U>where Self::Output: Into<U>, Self: Sized,
source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>where
F: FnOnce(Self::Output) -> Fut,
Fut: Future,
Self: Sized,
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>where F: FnOnce(Self::Output) -> Fut, Fut: Future, Self: Sized,
f
. Read moresource§fn left_future<B>(self) -> Either<Self, B>where
B: Future<Output = Self::Output>,
Self: Sized,
fn left_future<B>(self) -> Either<Self, B>where B: Future<Output = Self::Output>, Self: Sized,
source§fn right_future<A>(self) -> Either<A, Self>where
A: Future<Output = Self::Output>,
Self: Sized,
fn right_future<A>(self) -> Either<A, Self>where A: Future<Output = Self::Output>, Self: Sized,
source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where Self: Sized,
source§fn flatten(self) -> Flatten<Self>where
Self::Output: Future,
Self: Sized,
fn flatten(self) -> Flatten<Self>where Self::Output: Future, Self: Sized,
source§fn flatten_stream(self) -> FlattenStream<Self>where
Self::Output: Stream,
Self: Sized,
fn flatten_stream(self) -> FlattenStream<Self>where Self::Output: Stream, Self: Sized,
source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where Self: Sized,
poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read moresource§fn inspect<F>(self, f: F) -> Inspect<Self, F>where
F: FnOnce(&Self::Output),
Self: Sized,
fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: FnOnce(&Self::Output), Self: Sized,
source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where Self: Sized + UnwindSafe,
source§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where Self: Sized,
()
on completion and sends
its output to another future on a separate task. Read moresource§fn boxed<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>>where
Self: Sized + Send + 'a,
fn boxed<'a>( self ) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>>where Self: Sized + Send + 'a,
source§fn boxed_local<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>>where
Self: Sized + 'a,
fn boxed_local<'a>( self ) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>>where Self: Sized + 'a,
source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>.source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>.