Class: Protocol::HTTP2::LocalWindow

Inherits:
Window
  • Object
show all
Defined in:
lib/protocol/http2/window.rb

Overview

This is a window which efficiently maintains a desired capacity.

Constant Summary

Constants inherited from Window

Window::DEFAULT_CAPACITY

Instance Attribute Summary collapse

Attributes inherited from Window

#available, #capacity, #used

Instance Method Summary collapse

Methods inherited from Window

#available?, #consume, #expand, #full?

Constructor Details

#initialize(capacity = DEFAULT_CAPACITY, desired: nil) ⇒ LocalWindow

Returns a new instance of LocalWindow.



83
84
85
86
87
88
89
# File 'lib/protocol/http2/window.rb', line 83

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

Instance Attribute Details

#desiredObject

The desired capacity of the window.



92
93
94
# File 'lib/protocol/http2/window.rb', line 92

def desired
  @desired
end

Instance Method Details

#inspectObject



112
113
114
# File 'lib/protocol/http2/window.rb', line 112

def inspect
	"\#<#{self.class} available=#{@available} used=#{@used} capacity=#{@capacity} desired=#{@desired} #{limited? ? "limited" : nil}>"
end

#limited?Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
109
110
# File 'lib/protocol/http2/window.rb', line 103

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

#wantedObject



94
95
96
97
98
99
100
101
# File 'lib/protocol/http2/window.rb', line 94

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