Class: Protocol::HTTP2::Window
- Inherits:
-
Object
- Object
- Protocol::HTTP2::Window
- Defined in:
- lib/protocol/http2/window.rb
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
- #consume(amount) ⇒ Object
- #expand(amount) ⇒ Object
-
#full? ⇒ Boolean
The window is completely full?.
-
#initialize(capacity = DEFAULT_CAPACITY) ⇒ Window
constructor
A new instance of Window.
- #inspect ⇒ Object (also: #to_s)
- #limited? ⇒ Boolean
- #wanted ⇒ Object
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
#available ⇒ Object (readonly)
Returns the value of attribute available.
48 49 50 |
# File 'lib/protocol/http2/window.rb', line 48 def available @available end |
#capacity ⇒ Object
Returns the value of attribute capacity.
28 29 30 |
# File 'lib/protocol/http2/window.rb', line 28 def capacity @capacity end |
#used ⇒ Object (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
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 (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?
23 24 25 |
# File 'lib/protocol/http2/window.rb', line 23 def full? @available <= 0 end |
#inspect ⇒ Object 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
70 71 72 |
# File 'lib/protocol/http2/window.rb', line 70 def limited? @available < (@capacity / 2) end |
#wanted ⇒ Object
66 67 68 |
# File 'lib/protocol/http2/window.rb', line 66 def wanted @used end |