diff --git a/neqo-transport/src/fc.rs b/neqo-transport/src/fc.rs index 5ddfce6463..d619fd8e82 100644 --- a/neqo-transport/src/fc.rs +++ b/neqo-transport/src/fc.rs @@ -64,15 +64,16 @@ where } } - /// Update the maximum. Returns `true` if the change was an increase. - pub fn update(&mut self, limit: u64) -> bool { + /// Update the maximum. Returns `Some` with the updated available flow + /// control if the change was an increase and `None` otherwise. + pub fn update(&mut self, limit: u64) -> Option { debug_assert!(limit < u64::MAX); if limit > self.limit { self.limit = limit; self.blocked_frame = false; - true + Some(self.available()) } else { - false + None } } diff --git a/neqo-transport/src/send_stream.rs b/neqo-transport/src/send_stream.rs index a80a776ca0..2ba1486361 100644 --- a/neqo-transport/src/send_stream.rs +++ b/neqo-transport/src/send_stream.rs @@ -1220,9 +1220,9 @@ impl SendStream { &mut self.state { let previous_limit = fc.available(); - fc.update(limit); - let current_limit = fc.available(); - self.maybe_emit_writable_event(previous_limit, current_limit); + if let Some(current_limit) = fc.update(limit) { + self.maybe_emit_writable_event(previous_limit, current_limit); + } } } @@ -2486,7 +2486,7 @@ mod tests { // Increasing conn max (conn:4, stream:4) will unblock but not emit // event b/c that happens in Connection::emit_frame() (tested in // connection.rs) - assert!(conn_fc.borrow_mut().update(4)); + assert!(conn_fc.borrow_mut().update(4).is_some()); assert_eq!(conn_events.events().count(), 0); assert_eq!(s.avail(), 2); assert_eq!(s.send(b"hello").unwrap(), 2); @@ -2528,14 +2528,14 @@ mod tests { // Increasing the connection limit (conn:10, stream:0, watermark: 3) will not generate // event or allow sending anything. Stream is constrained by stream limit. - assert!(conn_fc.borrow_mut().update(10)); + assert!(conn_fc.borrow_mut().update(10).is_some()); assert_eq!(s.avail(), 0); assert_eq!(conn_events.events().count(), 0); // Increasing the connection limit further (conn:11, stream:0, watermark: 3) will not // generate event or allow sending anything. Stream wasn't constrained by connection // limit before. - assert!(conn_fc.borrow_mut().update(11)); + assert!(conn_fc.borrow_mut().update(11).is_some()); assert_eq!(s.avail(), 0); assert_eq!(conn_events.events().count(), 0); diff --git a/neqo-transport/src/streams.rs b/neqo-transport/src/streams.rs index acfee50df2..d0004ece3e 100644 --- a/neqo-transport/src/streams.rs +++ b/neqo-transport/src/streams.rs @@ -477,10 +477,7 @@ impl Streams { pub fn handle_max_data(&mut self, maximum_data: u64) { let previous_limit = self.sender_fc.borrow().available(); - let conn_credit_increased = self.sender_fc.borrow_mut().update(maximum_data); - let current_limit = self.sender_fc.borrow().available(); - - if conn_credit_increased { + if let Some(current_limit) = self.sender_fc.borrow_mut().update(maximum_data) { for (_id, ss) in &mut self.send { ss.maybe_emit_writable_event(previous_limit, current_limit); } @@ -528,7 +525,10 @@ impl Streams { } pub fn handle_max_streams(&mut self, stream_type: StreamType, maximum_streams: u64) { - if self.local_stream_limits[stream_type].update(maximum_streams) { + let increased = self.local_stream_limits[stream_type] + .update(maximum_streams) + .is_some(); + if increased { self.events.send_stream_creatable(stream_type); } }