From a1f9215e760b042becd61067b76d966ae0a4c239 Mon Sep 17 00:00:00 2001 From: boxdot Date: Mon, 3 May 2021 16:12:01 +0200 Subject: [PATCH] Do not use `Instant::now` when zero reset streams are configured. This allows to use `h2` on wasm platforms which lack an `Instant::now` implementation by setting the number of streams to 0 with: `h2::client::Builder::max_concurrent_reset_streams`. --- src/proto/streams/recv.rs | 16 +++++++++------- src/proto/streams/store.rs | 4 ++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/proto/streams/recv.rs b/src/proto/streams/recv.rs index 252fd8687..1f30450fe 100644 --- a/src/proto/streams/recv.rs +++ b/src/proto/streams/recv.rs @@ -866,13 +866,15 @@ impl Recv { } pub fn clear_expired_reset_streams(&mut self, store: &mut Store, counts: &mut Counts) { - let now = Instant::now(); - let reset_duration = self.reset_duration; - while let Some(stream) = self.pending_reset_expired.pop_if(store, |stream| { - let reset_at = stream.reset_at.expect("reset_at must be set if in queue"); - now - reset_at > reset_duration - }) { - counts.transition_after(stream, true); + if !self.pending_reset_expired.is_empty() { + let now = Instant::now(); + let reset_duration = self.reset_duration; + while let Some(stream) = self.pending_reset_expired.pop_if(store, |stream| { + let reset_at = stream.reset_at.expect("reset_at must be set if in queue"); + now - reset_at > reset_duration + }) { + counts.transition_after(stream, true); + } } } diff --git a/src/proto/streams/store.rs b/src/proto/streams/store.rs index 9b66cf904..ac58f43ac 100644 --- a/src/proto/streams/store.rs +++ b/src/proto/streams/store.rs @@ -304,6 +304,10 @@ where None } + pub fn is_empty(&self) -> bool { + self.indices.is_none() + } + pub fn pop_if<'a, R, F>(&mut self, store: &'a mut R, f: F) -> Option> where R: Resolve,