Module: Protocol::HTTP2::FlowControlled
- Included in:
- Connection, Stream
- Defined in:
- lib/protocol/http2/flow_controlled.rb
Instance Method Summary collapse
-
#available_frame_size(maximum_frame_size = self.maximum_frame_size) ⇒ Object
This could be negative if the window has been overused due to a change in initial window size.
- #available_size ⇒ Object
- #consume_local_window(frame) ⇒ Object
-
#consume_remote_window(frame) ⇒ Object
Keep track of the amount of data sent, and fail if is too much.
- #receive_window_update(frame) ⇒ Object
- #request_window_update ⇒ Object
-
#send_window_update(window_increment) ⇒ Object
Notify the remote end that we are prepared to receive more data:.
- #update_local_window(frame) ⇒ Object
-
#window_updated(size) ⇒ Boolean
The window has been expanded by the given amount.
Instance Method Details
#available_frame_size(maximum_frame_size = self.maximum_frame_size) ⇒ Object
This could be negative if the window has been overused due to a change in initial window size.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/protocol/http2/flow_controlled.rb', line 17 def available_frame_size(maximum_frame_size = self.maximum_frame_size) available_size = self.available_size # puts "available_size=#{available_size} maximum_frame_size=#{maximum_frame_size}" if available_size < maximum_frame_size return available_size else return maximum_frame_size end end |
#available_size ⇒ Object
12 13 14 |
# File 'lib/protocol/http2/flow_controlled.rb', line 12 def available_size @remote_window.available end |
#consume_local_window(frame) ⇒ Object
48 49 50 51 52 |
# File 'lib/protocol/http2/flow_controlled.rb', line 48 def consume_local_window(frame) # For flow-control calculations, the 9-octet frame header is not counted. amount = frame.length @local_window.consume(amount) end |
#consume_remote_window(frame) ⇒ Object
Keep track of the amount of data sent, and fail if is too much.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/protocol/http2/flow_controlled.rb', line 30 def consume_remote_window(frame) amount = frame.length # Frames with zero length with the END_STREAM flag set (that is, an empty DATA frame) MAY be sent if there is no available space in either flow-control window. if amount.zero? and frame.end_stream? # It's okay, we can send. No need to consume, it's empty anyway. elsif amount >= 0 and amount <= @remote_window.available @remote_window.consume(amount) else raise FlowControlError, "Trying to send #{frame.length} bytes, exceeded window size: #{@remote_window.available} (#{@remote_window})" end end |
#receive_window_update(frame) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/protocol/http2/flow_controlled.rb', line 70 def receive_window_update(frame) amount = frame.unpack # Async.logger.info(self) {"expanding remote_window=#{@remote_window} by #{amount}"} if amount != 0 @remote_window.(amount) else raise ProtocolError, "Invalid window size increment: #{amount}!" end # puts "expanded remote_window=#{@remote_window} by #{amount}" end |
#request_window_update ⇒ Object
54 55 56 57 58 |
# File 'lib/protocol/http2/flow_controlled.rb', line 54 def request_window_update if @local_window.limited? self.send_window_update(@local_window.wanted) end end |
#send_window_update(window_increment) ⇒ Object
Notify the remote end that we are prepared to receive more data:
61 62 63 64 65 66 67 68 |
# File 'lib/protocol/http2/flow_controlled.rb', line 61 def send_window_update(window_increment) frame = WindowUpdateFrame.new(self.id) frame.pack window_increment write_frame(frame) @local_window.(window_increment) end |
#update_local_window(frame) ⇒ Object
43 44 45 46 |
# File 'lib/protocol/http2/flow_controlled.rb', line 43 def update_local_window(frame) consume_local_window(frame) request_window_update end |
#window_updated(size) ⇒ Boolean
The window has been expanded by the given amount.
87 88 89 |
# File 'lib/protocol/http2/flow_controlled.rb', line 87 def window_updated(size) return false end |