From 392b42c68b2a2e4c5beb60f59048b4813dae7c35 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 3 Apr 2015 00:13:25 +0000 Subject: wbuf: store busy signal inside this object This should make it easier to track state for asynchronous proxy_pass buffering. --- lib/yahns/http_response.rb | 4 ++-- lib/yahns/wbuf.rb | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb index 0b0296f..1ef2bbf 100644 --- a/lib/yahns/http_response.rb +++ b/lib/yahns/http_response.rb @@ -67,7 +67,7 @@ module Yahns::HttpResponse # :nodoc: alive = Yahns::StreamFile.new(body, alive, offset, count) body = nil end - wbuf = Yahns::Wbuf.new(body, alive, self.class.output_buffer_tmpdir) + wbuf = Yahns::Wbuf.new(body, alive, self.class.output_buffer_tmpdir, ret) rv = wbuf.wbuf_write(self, header) body.each { |chunk| rv = wbuf.wbuf_write(self, chunk) } if body wbuf_maybe(wbuf, rv) @@ -199,7 +199,7 @@ module Yahns::HttpResponse # :nodoc: chunk = rv # hope the skb grows when we loop into the trywrite when :wait_writable, :wait_readable if k.output_buffering - wbuf = Yahns::Wbuf.new(body, alive, k.output_buffer_tmpdir) + wbuf = Yahns::Wbuf.new(body, alive, k.output_buffer_tmpdir, rv) rv = wbuf.wbuf_write(self, chunk) break else diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb index 4eed2c5..ba7ea0f 100644 --- a/lib/yahns/wbuf.rb +++ b/lib/yahns/wbuf.rb @@ -29,14 +29,15 @@ require_relative 'wbuf_common' # to be a scalability issue. class Yahns::Wbuf # :nodoc: include Yahns::WbufCommon + attr_reader :busy - def initialize(body, persist, tmpdir) + def initialize(body, persist, tmpdir, busy) @tmpio = nil @tmpdir = tmpdir @sf_offset = @sf_count = 0 @wbuf_persist = persist # whether or not we keep the connection alive @body = body - @bypass = false + @busy = busy # may be false end def wbuf_write(client, buf) @@ -47,8 +48,8 @@ class Yahns::Wbuf # :nodoc: when nil return # yay! hopefully we don't have to buffer again when :wait_writable, :wait_readable - @bypass = false # ugh, continue to buffering to file - end while @bypass + @busy = rv + end until @busy @tmpio ||= Yahns::TmpIO.new(@tmpdir) @sf_count += @tmpio.write(buf) @@ -57,6 +58,7 @@ class Yahns::Wbuf # :nodoc: @sf_count -= rv @sf_offset += rv when :wait_writable, :wait_readable + @busy = rv return rv else raise "BUG: #{rv.nil ? "EOF" : rv.inspect} on tmpio " \ @@ -67,7 +69,7 @@ class Yahns::Wbuf # :nodoc: # to disk if we can help it. @tmpio = @tmpio.close @sf_offset = 0 - @bypass = true + @busy = false nil end -- cgit v1.2.3-24-ge0c7