Module: Protocol::HTTP2::FlowControl
- Included in:
- Connection, Stream
- Defined in:
- lib/protocol/http2/flow_control.rb
Instance Method Summary collapse
- #available_frame_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
-
#send_window_update(window_increment) ⇒ Object
Notify the remote end that we are prepared to receive more data:.
- #window_updated ⇒ Object
Instance Method Details
#available_frame_size ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/protocol/http2/flow_control.rb', line 26 def available_frame_size maximum_frame_size = self.maximum_frame_size available_size = @remote_window.available # 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 |
#consume_local_window(frame) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/protocol/http2/flow_control.rb', line 53 def consume_local_window(frame) amount = frame.length @local_window.consume(amount) if @local_window.limited? self.send_window_update(@local_window.used) end end |
#consume_remote_window(frame) ⇒ Object
Keep track of the amount of data sent, and fail if is too much.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/protocol/http2/flow_control.rb', line 40 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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/protocol/http2/flow_control.rb', line 73 def receive_window_update(frame) was_full = @remote_window.full? amount = frame.unpack # puts "expand remote_window=#{@remote_window} by #{amount}" if amount != 0 @remote_window.(amount) else raise ProtocolError, "Invalid window size increment: #{amount}!" end self.window_updated if was_full end |
#send_window_update(window_increment) ⇒ Object
Notify the remote end that we are prepared to receive more data:
64 65 66 67 68 69 70 71 |
# File 'lib/protocol/http2/flow_control.rb', line 64 def send_window_update(window_increment) frame = WindowUpdateFrame.new(self.id) frame.pack window_increment write_frame(frame) @local_window.(window_increment) end |
#window_updated ⇒ Object
88 89 |
# File 'lib/protocol/http2/flow_control.rb', line 88 def window_updated end |