Class: Protocol::HTTP2::Window
- Inherits:
-
Object
- Object
- Protocol::HTTP2::Window
- Defined in:
- lib/protocol/http2/window.rb
Overview
Flow control window for managing HTTP/2 data flow.
Direct Known Subclasses
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
-
#available ⇒ Object
readonly
Returns the value of attribute available.
-
#capacity ⇒ Object
Returns the value of attribute capacity.
-
#used ⇒ Object
readonly
Returns the value of attribute used.
Instance Method Summary collapse
-
#available? ⇒ Boolean
Check if there is available window capacity.
-
#consume(amount) ⇒ Object
Consume a specific amount from the available window.
-
#expand(amount) ⇒ Object
Expand the window by a specific amount.
-
#full? ⇒ Boolean
The window is completely full?.
-
#initialize(capacity = DEFAULT_CAPACITY) ⇒ Window
constructor
Initialize a new flow control window.
-
#inspect ⇒ Object
(also: #to_s)
Get a string representation of the window.
-
#limited? ⇒ Boolean
Check if the window is limited and needs updating.
-
#wanted ⇒ Object
Get the amount of window that should be reclaimed.
Constructor Details
#initialize(capacity = DEFAULT_CAPACITY) ⇒ Window
Initialize a new flow control window.
15 16 17 18 19 20 21 22 |
# File 'lib/protocol/http2/window.rb', line 15 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
#available ⇒ Object (readonly)
Returns the value of attribute available.
52 53 54 |
# File 'lib/protocol/http2/window.rb', line 52 def available @available end |
#capacity ⇒ Object
Returns the value of attribute capacity.
30 31 32 |
# File 'lib/protocol/http2/window.rb', line 30 def capacity @capacity end |
#used ⇒ Object (readonly)
Returns the value of attribute used.
29 30 31 |
# File 'lib/protocol/http2/window.rb', line 29 def used @used end |
Instance Method Details
#available? ⇒ Boolean
Check if there is available window capacity.
56 57 58 |
# File 'lib/protocol/http2/window.rb', line 56 def available? @available > 0 end |
#consume(amount) ⇒ Object
Consume a specific amount from the available window.
47 48 49 50 |
# File 'lib/protocol/http2/window.rb', line 47 def consume(amount) @available -= amount @used += amount end |
#expand(amount) ⇒ Object
Expand the window by a specific amount.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/protocol/http2/window.rb', line 63 def (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?
25 26 27 |
# File 'lib/protocol/http2/window.rb', line 25 def full? @available <= 0 end |
#inspect ⇒ Object Also known as: to_s
Get a string representation of the window.
89 90 91 |
# File 'lib/protocol/http2/window.rb', line 89 def inspect "\#<#{self.class} available=#{@available} used=#{@used} capacity=#{@capacity}#{limited? ? " limited" : nil}>" end |
#limited? ⇒ Boolean
Check if the window is limited and needs updating.
83 84 85 |
# File 'lib/protocol/http2/window.rb', line 83 def limited? @available < (@capacity / 2) end |
#wanted ⇒ Object
Get the amount of window that should be reclaimed.
77 78 79 |
# File 'lib/protocol/http2/window.rb', line 77 def wanted @used end |