class Protocol::HTTP2::LocalWindow

This is a window which efficiently maintains a desired capacity.

def initialize(capacity = DEFAULT_CAPACITY, desired: nil)

@parameter desired [Integer] The desired window capacity.
@parameter capacity [Integer] The initial window capacity.
Initialize a local window with optional desired capacity.
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

def inspect

@returns [String] Human-readable local window information.
Get a string representation of the local window.
def inspect
	"\#<#{self.class} available=#{@available} used=#{@used} capacity=#{@capacity} desired=#{@desired} #{limited? ? "limited" : nil}>"
end

def limited?

@returns [Boolean] True if window needs updating based on desired capacity.
Check if the window is limited, considering desired capacity.
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 wanted

@returns [Integer] The amount needed to reach desired capacity or used space.
Get the amount of window that should be reclaimed, considering desired capacity.
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