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.
106 107 108 109 |
# File 'lib/http/2/flow_buffer.rb', line 106 def initialize @buffer = [] @bytesize = 0 end |
Instance Attribute Details
#bytesize ⇒ Object (readonly)
Returns the value of attribute bytesize.
104 105 106 |
# File 'lib/http/2/flow_buffer.rb', line 104 def bytesize @bytesize end |
Instance Method Details
#<<(frame) ⇒ Object
111 112 113 114 |
# File 'lib/http/2/flow_buffer.rb', line 111 def <<(frame) @buffer << frame @bytesize += frame[:payload].bytesize end |
#empty? ⇒ Boolean
116 117 118 |
# File 'lib/http/2/flow_buffer.rb', line 116 def empty? @bytesize.zero? end |
#retrieve(window_size) ⇒ Object
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 155 156 |
# File 'lib/http/2/flow_buffer.rb', line 120 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 == 0 && end_stream) @buffer.shift if frame_size > window_size payload = frame[:payload] chunk = frame.dup # Split frame so that it fits in the window # TODO: consider padding! frame_bytes = payload.byteslice(0, window_size) payload = payload.byteslice(window_size..-1) frame[:payload] = frame_bytes frame[:length] = frame_bytes.bytesize chunk[:payload] = payload chunk[:length] = payload.bytesize # 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 |