Add initial_max_send_streams() as builder option (#242)

This commit is contained in:
Darren Tsung
2018-03-16 11:58:06 -07:00
committed by Carl Lerche
parent 0cb3e648e9
commit 4595b54cfa
5 changed files with 62 additions and 5 deletions

View File

@@ -177,6 +177,7 @@ use tokio_io::io::WriteAll;
use std::fmt;
use std::marker::PhantomData;
use std::time::Duration;
use std::usize;
/// Performs the HTTP/2.0 connection handshake.
///
@@ -344,6 +345,12 @@ pub struct Builder {
/// Time to keep locally reset streams around before reaping.
reset_stream_duration: Duration,
/// Initial maximum number of locally initiated (send) streams.
/// After receiving a Settings frame from the remote peer,
/// the connection will overwrite this value with the
/// MAX_CONCURRENT_STREAMS specified in the frame.
initial_max_send_streams: usize,
/// Maximum number of locally reset streams to keep at a time.
reset_stream_max: usize,
@@ -671,6 +678,7 @@ impl Builder {
Builder {
reset_stream_duration: Duration::from_secs(proto::DEFAULT_RESET_STREAM_SECS),
reset_stream_max: proto::DEFAULT_RESET_STREAM_MAX,
initial_max_send_streams: usize::MAX,
settings: Default::default(),
stream_id: 1.into(),
}
@@ -838,6 +846,48 @@ impl Builder {
self
}
/// Sets the initial maximum of locally initiated (send) streams.
///
/// The initial settings will be overwritten by the remote peer when
/// the Settings frame is received. The new value will be set to the
/// `max_concurrent_streams()` from the frame.
///
/// This setting prevents the caller from exceeding this number of
/// streams that are counted towards the concurrency limit.
///
/// Sending streams past the limit returned by the peer will be treated
/// as a stream error of type PROTOCOL_ERROR or REFUSED_STREAM.
///
/// See [Section 5.1.2] in the HTTP/2.0 spec for more details.
///
/// [Section 5.1.2]: https://http2.github.io/http2-spec/#rfc.section.5.1.2
///
/// # Examples
///
/// ```
/// # extern crate h2;
/// # extern crate tokio_io;
/// # use tokio_io::*;
/// # use h2::client::*;
/// #
/// # fn doc<T: AsyncRead + AsyncWrite>(my_io: T)
/// # -> Handshake<T>
/// # {
/// // `client_fut` is a future representing the completion of the HTTP/2.0
/// // handshake.
/// let client_fut = Builder::new()
/// .initial_max_send_streams(1000)
/// .handshake(my_io);
/// # client_fut
/// # }
/// #
/// # pub fn main() {}
/// ```
pub fn initial_max_send_streams(&mut self, initial: usize) -> &mut Self {
self.initial_max_send_streams = initial;
self
}
/// Sets the maximum number of concurrent locally reset streams.
///
/// When a stream is explicitly reset by either calling
@@ -1218,6 +1268,7 @@ where
let connection = proto::Connection::new(codec, proto::Config {
next_stream_id: self.builder.stream_id,
initial_max_send_streams: self.builder.initial_max_send_streams,
reset_stream_duration: self.builder.reset_stream_duration,
reset_stream_max: self.builder.reset_stream_max,
settings: self.builder.settings.clone(),