Add max send buffer per stream option (#580)
This commit is contained in:
@@ -77,6 +77,7 @@ struct DynConnection<'a, B: Buf = Bytes> {
|
||||
pub(crate) struct Config {
|
||||
pub next_stream_id: StreamId,
|
||||
pub initial_max_send_streams: usize,
|
||||
pub max_send_buffer_size: usize,
|
||||
pub reset_stream_duration: Duration,
|
||||
pub reset_stream_max: usize,
|
||||
pub settings: frame::Settings,
|
||||
@@ -108,6 +109,7 @@ where
|
||||
.initial_window_size()
|
||||
.unwrap_or(DEFAULT_INITIAL_WINDOW_SIZE),
|
||||
initial_max_send_streams: config.initial_max_send_streams,
|
||||
local_max_buffer_size: config.max_send_buffer_size,
|
||||
local_next_stream_id: config.next_stream_id,
|
||||
local_push_enabled: config.settings.is_push_enabled().unwrap_or(true),
|
||||
extended_connect_protocol_enabled: config
|
||||
|
||||
@@ -33,3 +33,4 @@ pub type WindowSize = u32;
|
||||
pub const MAX_WINDOW_SIZE: WindowSize = (1 << 31) - 1;
|
||||
pub const DEFAULT_RESET_STREAM_MAX: usize = 10;
|
||||
pub const DEFAULT_RESET_STREAM_SECS: u64 = 30;
|
||||
pub const DEFAULT_MAX_SEND_BUFFER_SIZE: usize = 1024 * 400;
|
||||
|
||||
@@ -41,6 +41,9 @@ pub struct Config {
|
||||
/// MAX_CONCURRENT_STREAMS specified in the frame.
|
||||
pub initial_max_send_streams: usize,
|
||||
|
||||
/// Max amount of DATA bytes to buffer per stream.
|
||||
pub local_max_buffer_size: usize,
|
||||
|
||||
/// The stream ID to start the next local stream with
|
||||
pub local_next_stream_id: StreamId,
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ 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,
|
||||
|
||||
@@ -52,6 +55,7 @@ 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),
|
||||
@@ -333,14 +337,10 @@ impl Send {
|
||||
|
||||
/// Current available stream send capacity
|
||||
pub fn capacity(&self, stream: &mut store::Ptr) -> WindowSize {
|
||||
let available = stream.send_flow.available().as_size();
|
||||
let available = stream.send_flow.available().as_size() as usize;
|
||||
let buffered = stream.buffered_send_data;
|
||||
|
||||
if available as usize <= buffered {
|
||||
0
|
||||
} else {
|
||||
available - buffered as WindowSize
|
||||
}
|
||||
available.min(self.max_buffer_size).saturating_sub(buffered) as WindowSize
|
||||
}
|
||||
|
||||
pub fn poll_reset(
|
||||
|
||||
Reference in New Issue
Block a user