Class: HTTP2Next::FrameBuffer
- Inherits:
-
Object
- Object
- HTTP2Next::FrameBuffer
- Defined in:
- lib/http/2/next/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.
105 106 107 108 |
# File 'lib/http/2/next/flow_buffer.rb', line 105 def initialize @buffer = [] @bytesize = 0 end |
Instance Attribute Details
#bytesize ⇒ Object (readonly)
Returns the value of attribute bytesize.
103 104 105 |
# File 'lib/http/2/next/flow_buffer.rb', line 103 def bytesize @bytesize end |
Instance Method Details
#<<(frame) ⇒ Object
110 111 112 113 |
# File 'lib/http/2/next/flow_buffer.rb', line 110 def <<(frame) @buffer << frame @bytesize += frame[:payload].bytesize end |
#empty? ⇒ Boolean
115 116 117 |
# File 'lib/http/2/next/flow_buffer.rb', line 115 def empty? @bytesize == 0 end |
#retrieve(window_size) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/http/2/next/flow_buffer.rb', line 119 def retrieve(window_size) return if @buffer.empty? frame = @buffer.first 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 == 0 && end_stream) @buffer.shift if frame_size > window_size payload = frame.delete(:payload) chunk = frame.dup # Split frame so that it fits in the window # TODO: consider padding! frame[:payload] = payload.slice!(0, window_size) frame[:length] = frame[:payload].bytesize chunk[:length] = payload.bytesize chunk[:payload] = payload # if no longer last frame in sequence... frame[:flags] -= [:end_stream] if end_stream @buffer.unshift(chunk) @bytesize -= window_size else @bytesize -= frame_size end frame end |