Struct h2::proto::streams::prioritize::Prioritize

source ·
pub(super) struct Prioritize {
    pending_send: Queue<NextSend>,
    pending_capacity: Queue<NextSendCapacity>,
    pending_open: Queue<NextOpen>,
    flow: FlowControl,
    last_opened_id: StreamId,
    in_flight_data_frame: InFlightData,
    max_buffer_size: usize,
}
Expand description

§Warning

Queued streams are ordered by stream ID, as we need to ensure that lower-numbered streams are sent headers before higher-numbered ones. This is because “idle” stream IDs – those which have been initiated but have yet to receive frames – will be implicitly closed on receipt of a frame on a higher stream ID. If these queues was not ordered by stream IDs, some mechanism would be necessary to ensure that the lowest-numbered] idle stream is opened first.

Fields§

§pending_send: Queue<NextSend>

Queue of streams waiting for socket capacity to send a frame.

§pending_capacity: Queue<NextSendCapacity>

Queue of streams waiting for window capacity to produce data.

§pending_open: Queue<NextOpen>

Streams waiting for capacity due to max concurrency

The SendRequest handle is Clone. This enables initiating requests from many tasks. However, offering this capability while supporting backpressure at some level is tricky. If there are many SendRequest handles and a single stream becomes available, which handle gets assigned that stream? Maybe that handle is no longer ready to send a request.

The strategy used is to allow each SendRequest handle one buffered request. A SendRequest handle is ready to send a request if it has no associated buffered requests. This is the same strategy as mpsc in the futures library.

§flow: FlowControl

Connection level flow control governing sent data

§last_opened_id: StreamId

Stream ID of the last stream opened.

§in_flight_data_frame: InFlightData

What DATA frame is currently being sent in the codec.

§max_buffer_size: usize

The maximum amount of bytes a stream should buffer.

Implementations§

source§

impl Prioritize

source

pub fn new(config: &Config) -> Prioritize

source

pub(crate) fn max_buffer_size(&self) -> usize

source

pub fn queue_frame<B>( &mut self, frame: Frame<B>, buffer: &mut Buffer<Frame<B>>, stream: &mut Ptr<'_>, task: &mut Option<Waker>, )

Queue a frame to be sent to the remote

source

pub fn schedule_send(&mut self, stream: &mut Ptr<'_>, task: &mut Option<Waker>)

source

pub fn queue_open(&mut self, stream: &mut Ptr<'_>)

source

pub fn send_data<B>( &mut self, frame: Data<B>, buffer: &mut Buffer<Frame<B>>, stream: &mut Ptr<'_>, counts: &mut Counts, task: &mut Option<Waker>, ) -> Result<(), UserError>
where B: Buf,

Send a data frame

source

pub fn reserve_capacity( &mut self, capacity: u32, stream: &mut Ptr<'_>, counts: &mut Counts, )

Request capacity to send data

source

pub fn recv_stream_window_update( &mut self, inc: u32, stream: &mut Ptr<'_>, ) -> Result<(), Reason>

source

pub fn recv_connection_window_update( &mut self, inc: u32, store: &mut Store, counts: &mut Counts, ) -> Result<(), Reason>

source

pub fn reclaim_all_capacity( &mut self, stream: &mut Ptr<'_>, counts: &mut Counts, )

Reclaim all capacity assigned to the stream and re-assign it to the connection

source

pub fn reclaim_reserved_capacity( &mut self, stream: &mut Ptr<'_>, counts: &mut Counts, )

Reclaim just reserved capacity, not buffered capacity, and re-assign it to the connection

source

pub fn clear_pending_capacity(&mut self, store: &mut Store, counts: &mut Counts)

source

pub fn assign_connection_capacity<R>( &mut self, inc: u32, store: &mut R, counts: &mut Counts, )
where R: Resolve,

source

fn try_assign_capacity(&mut self, stream: &mut Ptr<'_>)

Request capacity to send data

source

pub fn poll_complete<T, B>( &mut self, cx: &mut Context<'_>, buffer: &mut Buffer<Frame<B>>, store: &mut Store, counts: &mut Counts, dst: &mut Codec<T, Prioritized<B>>, ) -> Poll<Result<()>>
where T: AsyncWrite + Unpin, B: Buf,

source

fn reclaim_frame<T, B>( &mut self, buffer: &mut Buffer<Frame<B>>, store: &mut Store, dst: &mut Codec<T, Prioritized<B>>, ) -> bool
where B: Buf,

Tries to reclaim a pending data frame from the codec.

Returns true if a frame was reclaimed.

When a data frame is written to the codec, it may not be written in its entirety (large chunks are split up into potentially many data frames). In this case, the stream needs to be reprioritized.

source

fn reclaim_frame_inner<B>( &mut self, buffer: &mut Buffer<Frame<B>>, store: &mut Store, frame: Data<Prioritized<B>>, ) -> bool
where B: Buf,

source

fn push_back_frame<B>( &mut self, frame: Frame<B>, buffer: &mut Buffer<Frame<B>>, stream: &mut Ptr<'_>, )

Push the frame to the front of the stream’s deque, scheduling the stream if needed.

source

pub fn clear_queue<B>( &mut self, buffer: &mut Buffer<Frame<B>>, stream: &mut Ptr<'_>, )

source

pub fn clear_pending_send(&mut self, store: &mut Store, counts: &mut Counts)

source

pub fn clear_pending_open(&mut self, store: &mut Store, counts: &mut Counts)

source

fn pop_frame<B>( &mut self, buffer: &mut Buffer<Frame<B>>, store: &mut Store, max_len: usize, counts: &mut Counts, ) -> Option<Frame<Prioritized<B>>>
where B: Buf,

source

fn pop_pending_open<'s>( &mut self, store: &'s mut Store, counts: &mut Counts, ) -> Option<Ptr<'s>>

Trait Implementations§

source§

impl Debug for Prioritize

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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>,

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more