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

Initialize a local window with optional desired capacity.



101
102
103
104
105
106
107
# File 'lib/protocol/http2/window.rb', line 101

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.



110
111
112
# File 'lib/protocol/http2/window.rb', line 110

def desired
  @desired
end

Instance Method Details

#inspectObject

Get a string representation of the local window.



136
137
138
# File 'lib/protocol/http2/window.rb', line 136

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

#limited?Boolean

Check if the window is limited, considering desired capacity.

Returns:

  • (Boolean)


125
126
127
128
129
130
131
132
# File 'lib/protocol/http2/window.rb', line 125

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

Get the amount of window that should be reclaimed, considering desired capacity.



114
115
116
117
118
119
120
121
# File 'lib/protocol/http2/window.rb', line 114

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