lib/protocol/http2/window_update_frame.rb in protocol-http2-0.14.2 vs lib/protocol/http2/window_update_frame.rb in protocol-http2-0.15.0
- old
+ new
@@ -1,25 +1,10 @@
-# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
+# frozen_string_literal: true
+# Released under the MIT License.
+# Copyright, 2019-2023, by Samuel Williams.
+
require_relative 'frame'
module Protocol
module HTTP2
class Window
@@ -42,10 +27,16 @@
attr :capacity
# When the value of SETTINGS_INITIAL_WINDOW_SIZE changes, a receiver MUST adjust the size of all stream flow-control windows that it maintains by the difference between the new value and the old value.
def capacity= value
difference = value - @capacity
+
+ # An endpoint MUST treat a change to SETTINGS_INITIAL_WINDOW_SIZE that causes any flow-control window to exceed the maximum size as a connection error of type FLOW_CONTROL_ERROR.
+ if (@available + difference) > MAXIMUM_ALLOWED_WINDOW_SIZE
+ raise FlowControlError, "Changing window size by #{difference} caused overflow: #{@available + difference} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}!"
+ end
+
@available += difference
@capacity = value
end
def consume(amount)
@@ -58,29 +49,31 @@
def available?
@available > 0
end
def expand(amount)
+ available = @available + amount
+
+ if available > MAXIMUM_ALLOWED_WINDOW_SIZE
+ raise FlowControlError, "Expanding window by #{amount} caused overflow: #{available} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}!"
+ end
+
# puts "expand(#{amount}) @available=#{@available}"
@available += amount
@used -= amount
-
- if @available > MAXIMUM_ALLOWED_WINDOW_SIZE
- raise FlowControlError, "Expanding window by #{amount} caused overflow: #{@available} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}!"
- end
end
def wanted
@used
end
def limited?
@available < (@capacity / 2)
end
- def to_s
- "\#<Window used=#{@used} available=#{@available} capacity=#{@capacity}>"
+ def inspect
+ "\#<#{self.class} used=#{@used} available=#{@available} capacity=#{@capacity}>"
end
end
# This is a window which efficiently maintains a desired capacity.
class LocalWindow < Window
@@ -100,10 +93,14 @@
@used
end
end
def limited?
- @available < ((@desired || @capacity) / 2)
+ if @desired
+ @available < @desired
+ else
+ super
+ end
end
end
# The WINDOW_UPDATE frame is used to implement flow control.
#