class LocalWindow
This is a window which efficiently maintains a desired capacity.
Definitions
def initialize(capacity = DEFAULT_CAPACITY, desired: nil)
Initialize a local window with optional desired capacity.
Signature
-
parameter
capacity
Integer
The initial window capacity.
-
parameter
desired
Integer
The desired window capacity.
Implementation
def initialize(capacity = DEFAULT_CAPACITY, desired: nil)
super(capacity)
# The desired capacity of the window, may be bigger than the initial capacity.
# If that is the case, we will likely send a window update to the remote end to increase the capacity.
@desired = desired
end
attr_accessor :desired
The desired capacity of the window.
def wanted
Get the amount of window that should be reclaimed, considering desired capacity.
Signature
-
returns
Integer
The amount needed to reach desired capacity or used space.
Implementation
def wanted
if @desired
# We must send an update which allows at least @desired bytes to be sent.
(@desired - @capacity) + @used
else
super
end
end
def limited?
Check if the window is limited, considering desired capacity.
Signature
-
returns
Boolean
True if window needs updating based on desired capacity.
Implementation
def limited?
if @desired
# Do not send window updates until we are less than half the desired capacity:
@available < (@desired / 2)
else
super
end
end
def inspect
Get a string representation of the local window.
Signature
-
returns
String
Human-readable local window information.
Implementation
def inspect
"\#<#{self.class} available=#{@available} used=#{@used} capacity=#{@capacity} desired=#{@desired} #{limited? ? "limited" : nil}>"
end