aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plum/server
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-11-03 14:42:14 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-11-03 14:42:14 +0900
commitedec99d21afea23fc2592c71c3f3a717d3af16d0 (patch)
treeda36c8b6bf600002f57019ed7bdad67b335668c7 /lib/plum/server
parent3bec944cea2d7c5f09198747e9e33c4cfdbb5cd4 (diff)
downloadplum-edec99d21afea23fc2592c71c3f3a717d3af16d0.tar.gz
connection: move reserve_stream to ServerConnection
Diffstat (limited to 'lib/plum/server')
-rw-r--r--lib/plum/server/connection.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/plum/server/connection.rb b/lib/plum/server/connection.rb
index a801d92..c12ef00 100644
--- a/lib/plum/server/connection.rb
+++ b/lib/plum/server/connection.rb
@@ -2,7 +2,29 @@
using Plum::BinaryString
module Plum
class ServerConnection < Connection
+ def initialize(writer, local_settings = {})
+ super(writer, local_settings)
+
+ @state = :waiting_preface
+ end
+
+ # Reserves a new stream to server push.
+ # @param args [Hash] The argument to pass to Stram.new.
+ def reserve_stream(**args)
+ next_id = @max_even_stream_id + 2
+ stream = new_stream(next_id, state: :reserved_local, **args)
+ stream
+ end
+
private
+ def consume_buffer
+ if @state == :waiting_preface
+ negotiate!
+ end
+
+ super
+ end
+
def negotiate!
unless CLIENT_CONNECTION_PREFACE.start_with?(@buffer.byteslice(0, 24))
raise ConnectionError.new(:protocol_error) # (MAY) send GOAWAY. sending.