# -*- encoding: binary -*- # Copyright (C) 2016 all contributors # License: GPL-3.0+ # frozen_string_literal: true require_relative 'wbuf_common' # This is only used for "proxy_buffering: false" class Yahns::WbufLite # :nodoc: include Yahns::WbufCommon attr_reader :busy def initialize(req_res) @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 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 end # called by Yahns::HttpClient#step_write def wbuf_flush(client) sym = do_write(client, @buf) and return sym # :wait_writable/:wait_readable # resume reading client.hijack_cleanup Thread.current[:yahns_queue].queue_mod(@req_res, Yahns::Queue::QEV_RD) :ignore rescue @req_res.close raise end end