Skip to content

Commit 978c712

Browse files
authored
add Connection::max_concurrent_send_streams (#513)
This PR adds accessors to `client::Connection` and `server::Connection` that return the send stream concurrency limit on that connection, as negotiated by the remote peer. This is part of issue #512. I think we probably ought to expose similar accessors for other settings, but I thought it was better to add each one in a separate, focused PR. Signed-off-by: Eliza Weisman <[email protected]>
1 parent 2c8c847 commit 978c712

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

src/client.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,19 @@ where
12281228
pub fn ping_pong(&mut self) -> Option<PingPong> {
12291229
self.inner.take_user_pings().map(PingPong::new)
12301230
}
1231+
1232+
/// Returns the maximum number of concurrent streams that may be initiated
1233+
/// by this client.
1234+
///
1235+
/// This limit is configured by the server peer by sending the
1236+
/// [`SETTINGS_MAX_CONCURRENT_STREAMS` parameter][settings] in a `SETTINGS`
1237+
/// frame. This method returns the currently acknowledged value recieved
1238+
/// from the remote.
1239+
///
1240+
/// [settings]: https://tools.ietf.org/html/rfc7540#section-5.1.2
1241+
pub fn max_concurrent_send_streams(&self) -> usize {
1242+
self.inner.max_send_streams()
1243+
}
12311244
}
12321245

12331246
impl<T, B> Future for Connection<T, B>

src/proto/connection.rs

+6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ where
120120
self.settings.send_settings(settings)
121121
}
122122

123+
/// Returns the maximum number of concurrent streams that may be initiated
124+
/// by this peer.
125+
pub(crate) fn max_send_streams(&self) -> usize {
126+
self.streams.max_send_streams()
127+
}
128+
123129
/// Returns `Ready` when the connection is ready to receive a frame.
124130
///
125131
/// Returns `RecvError` as this may raise errors that are caused by delayed

src/proto/streams/counts.rs

+6
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ impl Counts {
167167
}
168168
}
169169

170+
/// Returns the maximum number of streams that can be initiated by this
171+
/// peer.
172+
pub(crate) fn max_send_streams(&self) -> usize {
173+
self.max_send_streams
174+
}
175+
170176
fn dec_num_streams(&mut self, stream: &mut store::Ptr) {
171177
assert!(stream.is_counted);
172178

src/proto/streams/streams.rs

+4
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,10 @@ where
836836
Ok(())
837837
}
838838

839+
pub(crate) fn max_send_streams(&self) -> usize {
840+
self.inner.lock().unwrap().counts.max_send_streams()
841+
}
842+
839843
#[cfg(feature = "unstable")]
840844
pub fn num_active_streams(&self) -> usize {
841845
let me = self.inner.lock().unwrap();

src/server.rs

+13
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,19 @@ where
529529
pub fn ping_pong(&mut self) -> Option<PingPong> {
530530
self.connection.take_user_pings().map(PingPong::new)
531531
}
532+
533+
/// Returns the maximum number of concurrent streams that may be initiated
534+
/// by the server on this connection.
535+
///
536+
/// This limit is configured by the client peer by sending the
537+
/// [`SETTINGS_MAX_CONCURRENT_STREAMS` parameter][settings] in a `SETTINGS`
538+
/// frame. This method returns the currently acknowledged value recieved
539+
/// from the remote.
540+
///
541+
/// [settings]: https://tools.ietf.org/html/rfc7540#section-5.1.2
542+
pub fn max_concurrent_send_streams(&self) -> usize {
543+
self.connection.max_send_streams()
544+
}
532545
}
533546

534547
#[cfg(feature = "stream")]

0 commit comments

Comments
 (0)