Skip to content

Commit

Permalink
Have update() return available amount
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Apr 30, 2024
1 parent de0588c commit f5f1bb0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
9 changes: 5 additions & 4 deletions neqo-transport/src/fc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> {
debug_assert!(limit < u64::MAX);
if limit > self.limit {
self.limit = limit;
self.blocked_frame = false;
true
Some(self.available())
} else {
false
None
}
}

Expand Down
12 changes: 6 additions & 6 deletions neqo-transport/src/send_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions neqo-transport/src/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit f5f1bb0

Please sign in to comment.