class Protocol::HTTP2::Window
Flow control window for managing HTTP/2 data flow.
def available?
Check if there is available window capacity.
def available? @available > 0 end
def capacity= 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)
Consume a specific amount from the available window.
def consume(amount) @available -= amount @used += amount end
def expand(amount)
@parameter amount [Integer] The amount to expand the window by.
Expand the window by a specific amount.
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 end
def full?
def full? @available <= 0 end
def initialize(capacity = DEFAULT_CAPACITY)
Initialize a new flow control window.
def initialize(capacity = DEFAULT_CAPACITY) # This is the main field required: @available = capacity # These two fields are primarily used for efficiently sending window updates: @used = 0 @capacity = capacity end
def inspect
Get a string representation of the window.
def inspect "\#<#{self.class} available=#{@available} used=#{@used} capacity=#{@capacity}#{limited? ? " limited" : nil}>" end
def limited?
Check if the window is limited and needs updating.
def limited? @available < (@capacity / 2) end
def wanted
Get the amount of window that should be reclaimed.
def wanted @used end