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 |
# 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 if available_size < maximum_frame_size return available_size else return maximum_frame_size end end |
#consume_local_window(frame) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/protocol/http2/flow_control.rb', line 51 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.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/protocol/http2/flow_control.rb', line 38 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
71 72 73 74 75 76 77 78 |
# File 'lib/protocol/http2/flow_control.rb', line 71 def receive_window_update(frame) was_full = @remote_window.full? # puts "expand remote_window=#{@remote_window} by #{frame.unpack}" @remote_window.(frame.unpack) 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:
62 63 64 65 66 67 68 69 |
# File 'lib/protocol/http2/flow_control.rb', line 62 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
80 81 |
# File 'lib/protocol/http2/flow_control.rb', line 80 def window_updated end |