Protocol::HTTP2SourceProtocolHTTP2Window

class Window

Definitions

DEFAULT_CAPACITY = 0xFFFF

When an HTTP/2 connection is first established, new streams are created with an initial flow-control window size of 65,535 octets. The connection flow-control window is also 65,535 octets.

def initialize(capacity = DEFAULT_CAPACITY)

Implementation

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 full?

The window is completely full?

Implementation

def full?
	@available <= 0
end

def capacity= value

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.

Implementation

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