Struct FlowControl

struct FlowControl { ... }

A handle to release window capacity to a remote stream.

This type allows the caller to manage inbound data flow control. The caller is expected to call release_capacity after dropping data frames.

Overview

Each stream has a window size. This window size is the maximum amount of inbound data that can be in-flight. In-flight data is defined as data that has been received, but not yet released.

When a stream is created, the window size is set to the connection's initial window size value. When a data frame is received, the window size is then decremented by size of the data frame before the data is provided to the caller. As the caller finishes using the data, release_capacity must be called. This will then increment the window size again, allowing the peer to send more data.

There is also a connection level window as well as the stream level window. Received data counts against the connection level window as well and calls to release_capacity will also increment the connection level window.

Sending WINDOW_UPDATE frames

WINDOW_UPDATE frames will not be sent out for every call to release_capacity, as this would end up slowing down the protocol. Instead, h2 waits until the window size is increased to a certain threshold and then sends out a single WINDOW_UPDATE frame representing all the calls to release_capacity since the last WINDOW_UPDATE frame.

This essentially batches window updating.

Scenarios

Following is a basic scenario with an HTTP/2 connection containing a single active stream.

Implementations

impl FlowControl

fn stream_id(self: &Self) -> StreamId

Returns the stream ID of the stream whose capacity will be released by this FlowControl.

fn available_capacity(self: &Self) -> isize

Get the current available capacity of data this stream could receive.

fn used_capacity(self: &Self) -> usize

Get the currently used capacity for this stream.

This is the amount of bytes that can be released back to the remote.

fn release_capacity(self: &mut Self, sz: usize) -> Result<(), Error>

Release window capacity back to remote stream.

This releases capacity back to the stream level and the connection level windows. Both window sizes will be increased by sz.

See struct level documentation for more details.

Errors

This function errors if increasing the receive window size by sz would result in a window size greater than the target window size. In other words, the caller cannot release more capacity than data has been received. If 1024 bytes of data have been received, at most 1024 bytes can be released.

impl Clone for FlowControl

fn clone(self: &Self) -> FlowControl

impl Debug for FlowControl

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

impl Freeze for FlowControl

impl RefUnwindSafe for FlowControl

impl Send for FlowControl

impl Sync for FlowControl

impl Unpin for FlowControl

impl UnsafeUnpin for FlowControl

impl UnwindSafe for FlowControl

impl<T> Any for FlowControl

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for FlowControl

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

impl<T> BorrowMut for FlowControl

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

impl<T> CloneToUninit for FlowControl

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for FlowControl

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for FlowControl

impl<T> ToOwned for FlowControl

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> WithSubscriber for FlowControl

impl<T, U> Into for FlowControl

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 FlowControl

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

impl<T, U> TryInto for FlowControl

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