diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-07-20 15:38:57 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-07-20 15:38:57 +0900 |
commit | 3eb1f1bafd64c5a41b1579391a938a69fab7d6b9 (patch) | |
tree | bd49d5b69d8d234ee8ddfaa2269e33460bc9706a /lib/plum/stream.rb | |
parent | 38cd4d08a400950056d6be21d8fcae6f62811d91 (diff) | |
download | plum-3eb1f1bafd64c5a41b1579391a938a69fab7d6b9.tar.gz |
stream: accept IO in send_data
Diffstat (limited to 'lib/plum/stream.rb')
-rw-r--r-- | lib/plum/stream.rb | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/plum/stream.rb b/lib/plum/stream.rb index a85b396..9a09799 100644 --- a/lib/plum/stream.rb +++ b/lib/plum/stream.rb @@ -139,21 +139,27 @@ module Plum def send_data(data, end_stream: ture) max = @connection.remote_settings[:max_frame_size] - data = data.dup - flags = [] - flags << :end_stream if end_stream - - while data.bytesize > max - fragment = data.shift(max) - send Frame.new(type: :data, - stream_id: id, - payload: fragment) + if data.is_a?(IO) + while !data.eof? && fragment = data.readpartial(max) + flags = (data.eof? && [:end_stream]) + send Frame.new(type: :data, + stream_id: id, + flags: flags, + payload: fragment) + end + else + data = data.to_s + pos = 0 + while pos <= data.bytesize # data may be empty string + p fragment = data.byteslice(pos, max) + pos += max + flags = (pos > data.bytesize) && [:end_stream] + send Frame.new(type: :data, + stream_id: id, + flags: flags, + payload: fragment) + end end - - send Frame.new(type: :data, - flags: flags, - stream_id: id, - payload: data) end def process_data(frame) |