lib/protocol/http2/window_update_frame.rb in protocol-http2-0.11.6 vs lib/protocol/http2/window_update_frame.rb in protocol-http2-0.12.0

- old
+ new

@@ -31,14 +31,10 @@ # These two fields are primarily used for efficiently sending window updates: @used = 0 @capacity = capacity end - def dup - return self.class.new(@capacity) - end - # The window is completely full? def full? @available <= 0 end @@ -71,15 +67,43 @@ 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}>" + end + end + + # This is a window which efficiently maintains a desired capacity. + class LocalWindow < Window + def initialize(capacity = 0xFFFF, desired: nil) + super(capacity) + + @desired = desired + end + + attr_accessor :desired + + def wanted + if @desired + # We must send an update which allows at least @desired bytes to be sent. + (@desired - @capacity) + @used + else + @used + end + end + + def limited? + @available < ((@desired || @capacity) / 2) end end # The WINDOW_UPDATE frame is used to implement flow control. #