Do not use Instant::now when zero reset streams are configured. (#537)

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`.
This commit is contained in:
boxdot
2021-05-05 18:28:45 +02:00
committed by GitHub
parent 361de985a0
commit 04570652b7
2 changed files with 13 additions and 7 deletions

View File

@@ -866,13 +866,15 @@ impl Recv {
} }
pub fn clear_expired_reset_streams(&mut self, store: &mut Store, counts: &mut Counts) { pub fn clear_expired_reset_streams(&mut self, store: &mut Store, counts: &mut Counts) {
let now = Instant::now(); if !self.pending_reset_expired.is_empty() {
let reset_duration = self.reset_duration; let now = Instant::now();
while let Some(stream) = self.pending_reset_expired.pop_if(store, |stream| { let reset_duration = self.reset_duration;
let reset_at = stream.reset_at.expect("reset_at must be set if in queue"); while let Some(stream) = self.pending_reset_expired.pop_if(store, |stream| {
now - reset_at > reset_duration 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); }) {
counts.transition_after(stream, true);
}
} }
} }

View File

@@ -304,6 +304,10 @@ where
None 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<store::Ptr<'a>> pub fn pop_if<'a, R, F>(&mut self, store: &'a mut R, f: F) -> Option<store::Ptr<'a>>
where where
R: Resolve, R: Resolve,