diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-07-26 15:03:31 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-07-26 15:03:31 +0900 |
commit | 6409ca5fdb111f0f8e5bb88379ee62de2fcc4247 (patch) | |
tree | 3f1542b34a8cd26e4075730c9378199cf950cf98 /lib/plum/stream.rb | |
parent | 02274784d12b9c896a7696fa6a1c9c163362bcf7 (diff) | |
download | plum-6409ca5fdb111f0f8e5bb88379ee62de2fcc4247.tar.gz |
stream: support stream depencency / weight
Diffstat (limited to 'lib/plum/stream.rb')
-rw-r--r-- | lib/plum/stream.rb | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/plum/stream.rb b/lib/plum/stream.rb index 61a09a2..d2774f9 100644 --- a/lib/plum/stream.rb +++ b/lib/plum/stream.rb @@ -2,15 +2,21 @@ using Plum::BinaryString module Plum class Stream - attr_reader :id, :state, :priority + attr_reader :id, :state + attr_reader :weight, :parent, :exclusive - def initialize(con, id, state: :idle) + def initialize(con, id, state: :idle, weight: 16, parent: nil, exclusive: false) @connection = con @id = id @state = state - @substate = nil @continuation = [] @callbacks = Hash.new {|hash, key| hash[key] = [] } + + update_dependency(weight: weight, parent: parent, exclusive: exclusive) + end + + def children + @connection.streams.select {|c| c.parent == self } end def reserve @@ -67,7 +73,7 @@ module Plum end def promise(headers) # TODO: fragment - stream = @connection.reserve_stream + stream = @connection.reserve_stream(weight: self.weight + 1, parent: self) payload = "".force_encoding(Encoding::BINARY) payload.push_uint32((0 << 31 | stream.id)) payload.push(@connection.hpack_encoder.encode(headers)) @@ -91,6 +97,19 @@ module Plum @callbacks[name].each {|cb| cb.call(*args) } end + def update_dependency(weight: nil, parent: nil, exclusive: nil) + @weight = weight unless weight.nil? + @parent = parent unless parent.nil? + @exclusive = exclusive unless exclusive.nil? + + if exclusive == true + @connection.streams[parent].children.each do |child| + next if child == self + child.parent = self + end + end + end + def send_headers(headers, end_stream:) max = @connection.remote_settings[:max_frame_size] encoded = @connection.hpack_encoder.encode(headers) @@ -225,6 +244,8 @@ module Plum e = esd >> 31 dependency_id = e & ~(1 << 31) weight = payload.uint8(4) + + update_dependency(weight: weight, parent: @connection.streams[dependency_id], exclusive: e) end def process_rst_stream(frame) |