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
impl Prioritize
pub fn new(config: &Config) -> Prioritize
pub(crate) fn max_buffer_size(&self) -> usize
sourcepub fn queue_frame<B>(
&mut self,
frame: Frame<B>,
buffer: &mut Buffer<Frame<B>>,
stream: &mut Ptr<'_>,
task: &mut Option<Waker>,
)
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
pub fn schedule_send(&mut self, stream: &mut Ptr<'_>, task: &mut Option<Waker>)
pub fn queue_open(&mut self, stream: &mut Ptr<'_>)
sourcepub 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,
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
sourcepub fn reserve_capacity(
&mut self,
capacity: u32,
stream: &mut Ptr<'_>,
counts: &mut Counts,
)
pub fn reserve_capacity( &mut self, capacity: u32, stream: &mut Ptr<'_>, counts: &mut Counts, )
Request capacity to send data
pub fn recv_stream_window_update( &mut self, inc: u32, stream: &mut Ptr<'_>, ) -> Result<(), Reason>
pub fn recv_connection_window_update( &mut self, inc: u32, store: &mut Store, counts: &mut Counts, ) -> Result<(), Reason>
sourcepub fn reclaim_all_capacity(
&mut self,
stream: &mut Ptr<'_>,
counts: &mut Counts,
)
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
sourcepub fn reclaim_reserved_capacity(
&mut self,
stream: &mut Ptr<'_>,
counts: &mut Counts,
)
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
pub fn clear_pending_capacity(&mut self, store: &mut Store, counts: &mut Counts)
pub fn assign_connection_capacity<R>(
&mut self,
inc: u32,
store: &mut R,
counts: &mut Counts,
)where
R: Resolve,
sourcefn try_assign_capacity(&mut self, stream: &mut Ptr<'_>)
fn try_assign_capacity(&mut self, stream: &mut Ptr<'_>)
Request capacity to send data
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<()>>
sourcefn reclaim_frame<T, B>(
&mut self,
buffer: &mut Buffer<Frame<B>>,
store: &mut Store,
dst: &mut Codec<T, Prioritized<B>>,
) -> boolwhere
B: Buf,
fn reclaim_frame<T, B>(
&mut self,
buffer: &mut Buffer<Frame<B>>,
store: &mut Store,
dst: &mut Codec<T, Prioritized<B>>,
) -> boolwhere
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.
fn reclaim_frame_inner<B>(
&mut self,
buffer: &mut Buffer<Frame<B>>,
store: &mut Store,
frame: Data<Prioritized<B>>,
) -> boolwhere
B: Buf,
sourcefn push_back_frame<B>(
&mut self,
frame: Frame<B>,
buffer: &mut Buffer<Frame<B>>,
stream: &mut Ptr<'_>,
)
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.