diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-19 13:53:56 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-19 13:53:56 +0900 |
commit | bb04410f89a81c3981bf15752e6802a5f1decaaa (patch) | |
tree | a45baac7b80dc959b014c01395224f4a1583bc94 /lib/plum | |
parent | dbab2c340fce13f3a2feec4e14836db34b6c988e (diff) | |
download | plum-bb04410f89a81c3981bf15752e6802a5f1decaaa.tar.gz |
connection: fix new stream ID handling
Diffstat (limited to 'lib/plum')
-rw-r--r-- | lib/plum/connection.rb | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/plum/connection.rb b/lib/plum/connection.rb index e426853..94f1cc4 100644 --- a/lib/plum/connection.rb +++ b/lib/plum/connection.rb @@ -74,7 +74,7 @@ module Plum # # @param args [Hash] The argument to pass to Stram.new. def reserve_stream(**args) - next_id = ((@streams.keys.last / 2).to_i + 1) * 2 + next_id = (@streams.keys.select(&:even?).max || 0) + 2 stream = new_stream(next_id, state: :reserved_local, **args) stream end @@ -98,10 +98,6 @@ module Plum end def new_stream(stream_id, **args) - if @streams.size > 0 && @streams.keys.max >= stream_id - raise Plum::ConnectionError.new(:protocol_error) - end - stream = Stream.new(self, stream_id, **args) callback(:stream, stream) @streams[stream_id] = stream @@ -142,7 +138,10 @@ module Plum if @streams.key?(frame.stream_id) stream = @streams[frame.stream_id] else - raise ConnectionError.new(:protocol_error) if frame.stream_id.even? # stream started by client must have odd ID + if frame.stream_id.even? || (@streams.size > 0 && @streams.keys.select(&:odd?).max >= frame.stream_id) + raise Plum::ConnectionError.new(:protocol_error) + end + stream = new_stream(frame.stream_id) end stream.receive_frame(frame) |