WIP: send flow control

This commit is contained in:
Carl Lerche
2017-08-09 14:16:32 -07:00
parent 87c4d36b0c
commit dfec401fdf
9 changed files with 170 additions and 89 deletions

View File

@@ -9,8 +9,8 @@ pub struct FlowControl {
/// Amount to be removed by future increments.
underflow: WindowSize,
/// The amount that has been incremented but not yet advertised (to the application or
/// the remote).
/// The amount that has been incremented but not yet advertised (to the
/// application or the remote).
next_window_update: WindowSize,
}
@@ -23,6 +23,14 @@ impl FlowControl {
}
}
pub fn has_capacity(&self) -> bool {
self.window_size > 0
}
pub fn window_size(&self) -> WindowSize {
self.window_size
}
/// Returns true iff `claim_window(sz)` would return succeed.
pub fn ensure_window<T>(&mut self, sz: WindowSize, err: T) -> Result<(), ConnectionError>
where T: Into<ConnectionError>,
@@ -49,7 +57,10 @@ impl FlowControl {
}
/// Increase the _unadvertised_ window capacity.
pub fn expand_window(&mut self, sz: WindowSize) {
pub fn expand_window(&mut self, sz: WindowSize)
-> Result<(), ConnectionError>
{
// TODO: Handle invalid increment
if sz <= self.underflow {
self.underflow -= sz;
return;
@@ -60,6 +71,7 @@ impl FlowControl {
self.underflow = 0;
}
/*
/// Obtains the unadvertised window update.
///
/// This does not apply the window update to `self`.
@@ -70,6 +82,7 @@ impl FlowControl {
Some(self.next_window_update)
}
}
*/
/// Obtains and applies an unadvertised window update.
pub fn apply_window_update(&mut self) -> Option<WindowSize> {