Class: Protocol::HTTP2::Window

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

Direct Known Subclasses

LocalWindow

Constant Summary collapse

DEFAULT_CAPACITY =

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.

0xFFFF

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capacity = DEFAULT_CAPACITY) ⇒ Window

Returns a new instance of Window.



13
14
15
16
17
18
19
20
# File 'lib/protocol/http2/window.rb', line 13

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

Instance Attribute Details

#availableObject (readonly)

Returns the value of attribute available.



48
49
50
# File 'lib/protocol/http2/window.rb', line 48

def available
  @available
end

#capacityObject

Returns the value of attribute capacity.



28
29
30
# File 'lib/protocol/http2/window.rb', line 28

def capacity
  @capacity
end

#usedObject (readonly)

Returns the value of attribute used.



27
28
29
# File 'lib/protocol/http2/window.rb', line 27

def used
  @used
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/protocol/http2/window.rb', line 50

def available?
	@available > 0
end

#consume(amount) ⇒ Object



43
44
45
46
# File 'lib/protocol/http2/window.rb', line 43

def consume(amount)
	@available -= amount
	@used += amount
end

#expand(amount) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/protocol/http2/window.rb', line 54

def expand(amount)
	available = @available + amount
	
	if available > MAXIMUM_ALLOWED_WINDOW_SIZE
		raise FlowControlError, "Expanding window by #{amount} caused overflow: #{available} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}!"
	end
	
	# puts "expand(#{amount}) @available=#{@available}"
	@available += amount
	@used -= amount
end

#full?Boolean

The window is completely full?

Returns:

  • (Boolean)


23
24
25
# File 'lib/protocol/http2/window.rb', line 23

def full?
	@available <= 0
end

#inspectObject Also known as: to_s



74
75
76
# File 'lib/protocol/http2/window.rb', line 74

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

#limited?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/protocol/http2/window.rb', line 70

def limited?
	@available < (@capacity / 2)
end

#wantedObject



66
67
68
# File 'lib/protocol/http2/window.rb', line 66

def wanted
	@used
end