Skip to content

Commit acb5734

Browse files
authored
Add pings count (#45)
1 parent d3d26b5 commit acb5734

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ntex-h2"
3-
version = "1.6.1"
3+
version = "1.6.2"
44
license = "MIT OR Apache-2.0"
55
authors = ["Nikolay Kim <[email protected]>"]
66
description = "An HTTP/2 client and server"

src/client/simple.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ impl SimpleClient {
152152
self.0.con.active_streams()
153153
}
154154

155+
#[doc(hidden)]
156+
/// Get number of active streams
157+
pub fn pings_count(&self) -> u16 {
158+
self.0.con.pings_count()
159+
}
160+
155161
#[doc(hidden)]
156162
/// Get access to underlining io object
157163
pub fn io_ref(&self) -> &IoRef {

src/connection.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ struct ConnectionState {
4343
readiness: RefCell<VecDeque<pool::Sender<()>>>,
4444

4545
rst_count: Cell<u32>,
46-
total_count: Cell<u32>,
46+
streams_count: Cell<u32>,
47+
pings_count: Cell<u16>,
4748

4849
// Local config
4950
local_config: Config,
@@ -105,7 +106,8 @@ impl Connection {
105106
active_remote_streams: Cell::new(0),
106107
active_local_streams: Cell::new(0),
107108
rst_count: Cell::new(0),
108-
total_count: Cell::new(0),
109+
streams_count: Cell::new(0),
110+
pings_count: Cell::new(0),
109111
readiness: RefCell::new(VecDeque::new()),
110112
next_stream_id: Cell::new(StreamId::new(1)),
111113
local_config: config,
@@ -391,6 +393,10 @@ impl Connection {
391393
pub(crate) fn recv_half(&self) -> RecvHalfConnection {
392394
RecvHalfConnection(self.0.clone())
393395
}
396+
397+
pub(crate) fn pings_count(&self) -> u16 {
398+
self.0.pings_count.get()
399+
}
394400
}
395401

396402
impl RecvHalfConnection {
@@ -498,7 +504,7 @@ impl RecvHalfConnection {
498504
} else {
499505
let stream = StreamRef::new(id, true, Connection(self.0.clone()));
500506
self.0.next_stream_id.set(id);
501-
self.0.total_count.set(self.0.total_count.get() + 1);
507+
self.0.streams_count.set(self.0.streams_count.get() + 1);
502508
self.0.streams.borrow_mut().insert(id, stream.clone());
503509
self.0
504510
.active_remote_streams
@@ -666,8 +672,8 @@ impl RecvHalfConnection {
666672

667673
fn update_rst_count(&self) -> Result<(), Either<ConnectionError, StreamErrorInner>> {
668674
let count = self.0.rst_count.get() + 1;
669-
let total_count = self.0.total_count.get();
670-
if total_count >= 10 && count >= total_count >> 1 {
675+
let streams_count = self.0.streams_count.get();
676+
if streams_count >= 10 && count >= streams_count >> 1 {
671677
Err(Either::Left(ConnectionError::ConcurrencyOverflow))
672678
} else {
673679
self.0.rst_count.set(count);
@@ -867,5 +873,6 @@ async fn ping(st: Connection, timeout: time::Seconds, io: IoRef) {
867873
counter += 1;
868874
st.unset_flags(ConnectionFlags::RECV_PONG);
869875
st.encode(frame::Ping::new(counter.to_be_bytes()));
876+
st.0.pings_count.set(st.0.pings_count.get() + 1);
870877
}
871878
}

0 commit comments

Comments
 (0)