From 8bd2ce70d04414d147639ed2e28ac5a40f78595a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 6 Jun 2016 03:06:29 +0000 Subject: wbuf_lite: fix write retries for OpenSSL sockets OpenSSL can't handle write retries if we append to an existing string. Thus we must preserve the same string object upon retrying. Do that by utilizing the underlying Wbuf class which could already handles it transparently using trysendfile. However, we still avoiding the subtlety of wbuf_close_common reliance we previously used. ref: commit 551e670281bea77e727a732ba94275265ccae5f6 ("fix output buffering with SSL_write") --- lib/yahns/wbuf_lite.rb | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) (limited to 'lib') 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 # License: GPL-3.0+ # 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 -- cgit v1.2.3-24-ge0c7