diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/yahns/wbuf_lite.rb | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/lib/yahns/wbuf_lite.rb b/lib/yahns/wbuf_lite.rb index 5f25b2e..afee1e9 100644 --- a/lib/yahns/wbuf_lite.rb +++ b/lib/yahns/wbuf_lite.rb @@ -2,49 +2,43 @@ # Copyright (C) 2016 all contributors <yahns-public@yhbt.net> # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true -require_relative 'wbuf_common' +require_relative 'wbuf' # This is only used for "proxy_buffering: false" -class Yahns::WbufLite # :nodoc: - include Yahns::WbufCommon +class Yahns::WbufLite < Yahns::Wbuf # :nodoc: attr_reader :busy def initialize(req_res) + super(nil, :ignore) @req_res = req_res - @busy = false - @buf = nil end - # called only by proxy_write in proxy_http_response def wbuf_write(client, buf) - buf = buf.join if Array === buf - buf = @buf << buf if @buf # unlikely - do_write(client, buf) # try our best to avoid string copying/appending + super + rescue + @req_res = @req_res.close if @req_res + raise end - def do_write(client, buf) - case rv = client.kgio_trywrite(buf) - when String - buf = rv # continue looping - when :wait_writable, :wait_readable - @buf = buf - return @busy = rv - when nil - @buf = nil - return @busy = false - end while true + def wbuf_flush(client) + super + rescue + @req_res = @req_res.close if @req_res + raise end # called by Yahns::HttpClient#step_write - def wbuf_flush(client) - sym = do_write(client, @buf) and return sym # :wait_writable/:wait_readable + def wbuf_close(client) + wbuf_abort - # resume reading - client.hijack_cleanup - Thread.current[:yahns_queue].queue_mod(@req_res, Yahns::Queue::QEV_RD) + # resume reading when @blocked is empty + if @req_res + client.hijack_cleanup + Thread.current[:yahns_queue].queue_mod(@req_res, Yahns::Queue::QEV_RD) + end :ignore rescue - @req_res.close + @req_res = @req_res.close if @req_res raise end end |