Class: HTTP2::FrameBuffer
- Inherits:
-
Object
- Object
- HTTP2::FrameBuffer
- Defined in:
- lib/http/2/flow_buffer.rb
Instance Attribute Summary collapse
-
#bytesize ⇒ Object
readonly
Returns the value of attribute bytesize.
Instance Method Summary collapse
- #<<(frame) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ FrameBuffer
constructor
A new instance of FrameBuffer.
- #retrieve(window_size) ⇒ Object
Constructor Details
#initialize ⇒ FrameBuffer
Returns a new instance of FrameBuffer.
120 121 122 123 |
# File 'lib/http/2/flow_buffer.rb', line 120 def initialize @buffer = [] @bytesize = 0 end |
Instance Attribute Details
#bytesize ⇒ Object (readonly)
Returns the value of attribute bytesize.
118 119 120 |
# File 'lib/http/2/flow_buffer.rb', line 118 def bytesize @bytesize end |
Instance Method Details
#<<(frame) ⇒ Object
125 126 127 128 |
# File 'lib/http/2/flow_buffer.rb', line 125 def <<(frame) @buffer << frame @bytesize += frame[:payload].bytesize end |
#empty? ⇒ Boolean
130 131 132 |
# File 'lib/http/2/flow_buffer.rb', line 130 def empty? @buffer.empty? end |
#retrieve(window_size) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/http/2/flow_buffer.rb', line 134 def retrieve(window_size) frame = @buffer.first or return frame_size = frame[:payload].bytesize end_stream = frame[:flags].include?(:end_stream) # 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. return if window_size <= 0 && !(frame_size.zero? && end_stream) if frame_size > window_size chunk = frame.dup payload = frame[:payload] # Split frame so that it fits in the window # TODO: consider padding! chunk[:payload] = payload.byteslice(0, window_size) chunk[:length] = window_size frame[:payload] = payload.byteslice(window_size..-1) frame[:length] = frame_size - window_size # if no longer last frame in sequence... chunk[:flags] -= [:end_stream] if end_stream @bytesize -= window_size chunk else @bytesize -= frame_size @buffer.shift end end |