Make SendStream::poll_capacity never return Ok(Some(0)) (#596)

Fixes #270
This commit is contained in:
Anthony Ramine
2022-01-19 19:49:53 +01:00
committed by GitHub
parent b949d6ef99
commit d92ba1c45b
5 changed files with 85 additions and 19 deletions

View File

@@ -51,6 +51,9 @@ pub(super) struct Prioritize {
/// What `DATA` frame is currently being sent in the codec.
in_flight_data_frame: InFlightData,
/// The maximum amount of bytes a stream should buffer.
max_buffer_size: usize,
}
#[derive(Debug, Eq, PartialEq)]
@@ -93,9 +96,14 @@ impl Prioritize {
flow,
last_opened_id: StreamId::ZERO,
in_flight_data_frame: InFlightData::Nothing,
max_buffer_size: config.local_max_buffer_size,
}
}
pub(crate) fn max_buffer_size(&self) -> usize {
self.max_buffer_size
}
/// Queue a frame to be sent to the remote
pub fn queue_frame<B>(
&mut self,
@@ -424,7 +432,7 @@ impl Prioritize {
tracing::trace!(capacity = assign, "assigning");
// Assign the capacity to the stream
stream.assign_capacity(assign);
stream.assign_capacity(assign, self.max_buffer_size);
// Claim the capacity from the connection
self.flow.claim_capacity(assign);
@@ -744,7 +752,7 @@ impl Prioritize {
// If the capacity was limited because of the
// max_send_buffer_size, then consider waking
// the send task again...
stream.notify_if_can_buffer_more();
stream.notify_if_can_buffer_more(self.max_buffer_size);
// Assign the capacity back to the connection that
// was just consumed from the stream in the previous

View File

@@ -28,9 +28,6 @@ pub(super) struct Send {
/// > the identified last stream.
max_stream_id: StreamId,
/// The maximum amount of bytes a stream should buffer.
max_buffer_size: usize,
/// Initial window size of locally initiated streams
init_window_sz: WindowSize,
@@ -55,7 +52,6 @@ impl Send {
pub fn new(config: &Config) -> Self {
Send {
init_window_sz: config.remote_init_window_sz,
max_buffer_size: config.local_max_buffer_size,
max_stream_id: StreamId::MAX,
next_stream_id: Ok(config.local_next_stream_id),
prioritize: Prioritize::new(config),
@@ -340,7 +336,9 @@ impl Send {
let available = stream.send_flow.available().as_size() as usize;
let buffered = stream.buffered_send_data;
available.min(self.max_buffer_size).saturating_sub(buffered) as WindowSize
available
.min(self.prioritize.max_buffer_size())
.saturating_sub(buffered) as WindowSize
}
pub fn poll_reset(

View File

@@ -260,30 +260,29 @@ impl Stream {
self.ref_count == 0 && !self.state.is_closed()
}
pub fn assign_capacity(&mut self, capacity: WindowSize) {
pub fn assign_capacity(&mut self, capacity: WindowSize, max_buffer_size: usize) {
debug_assert!(capacity > 0);
self.send_capacity_inc = true;
self.send_flow.assign_capacity(capacity);
tracing::trace!(
" assigned capacity to stream; available={}; buffered={}; id={:?}",
" assigned capacity to stream; available={}; buffered={}; id={:?}; max_buffer_size={}",
self.send_flow.available(),
self.buffered_send_data,
self.id
self.id,
max_buffer_size
);
// Only notify if the capacity exceeds the amount of buffered data
if self.send_flow.available() > self.buffered_send_data {
tracing::trace!(" notifying task");
self.notify_send();
}
self.notify_if_can_buffer_more(max_buffer_size);
}
/// If the capacity was limited because of the max_send_buffer_size,
/// then consider waking the send task again...
pub fn notify_if_can_buffer_more(&mut self) {
pub fn notify_if_can_buffer_more(&mut self, max_buffer_size: usize) {
let available = self.send_flow.available().as_size() as usize;
let buffered = self.buffered_send_data;
// Only notify if the capacity exceeds the amount of buffered data
if self.send_flow.available() > self.buffered_send_data {
if available.min(max_buffer_size) > buffered {
self.send_capacity_inc = true;
tracing::trace!(" notifying task");
self.notify_send();