Correctly notify StreamMultiplexer of SETTINGS changes. (#67)

Motivation:

The StreamMultiplexer and StreamChannels are responsible for sending
WINDOW_UPDATE frames, but they were never told if the user changed the
value of SETTINGS_INITIAL_WINDOW_SIZE. They should be.

Modifications:

- Send user events when SETTINGS_INITIAL_WINDOW_SIZE changes.
- Use those window events to change the target window size in
    HTTP2StreamChannel.
- Keep track of the last stream window size we knew.

Result:

Less chance of flow control mess.
This commit is contained in:
Cory Benfield authored and GitHub committed 2019-03-15 17:37:00 +00:00
1 parent 1138881931
commit 55daa4cd4e
9 files changed
+155 -8

No files matched your search

+17 -1
View File
@@ -19,6 +19,9 @@
struct InboundWindowManager {
private var targetWindowSize: Int32
// The last window size we were told about. Used when we get changes to SETTINGS_INITIAL_WINDOW_SIZE.
private var lastWindowSize: Int?
init(targetSize: Int32) {
assert(targetSize <= HTTP2FlowControlWindow.maxSize)
assert(targetSize >= 0)
@@ -26,7 +29,9 @@ struct InboundWindowManager {
self.targetWindowSize = targetSize
}
func newWindowSize(_ newSize: Int) -> Int? {
mutating func newWindowSize(_ newSize: Int) -> Int? {
self.lastWindowSize = newSize
// All math here happens on 64-bit ints, as it avoids overflow problems.
// The simplest case is where newSize >= targetWindowSize. In that case, we do nothing.
@@ -51,4 +56,15 @@ struct InboundWindowManager {
return Int(increment)
}
}
mutating func initialWindowSizeChanged(delta: Int) -> Int? {
self.targetWindowSize += Int32(delta)
if let lastWindowSize = self.lastWindowSize {
// The delta applies to the current window size as well.
return self.newWindowSize(lastWindowSize + delta)
} else {
return nil
}
}
}