about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-04-03 00:13:25 +0000
committerEric Wong <e@80x24.org>2015-04-03 00:14:33 +0000
commit392b42c68b2a2e4c5beb60f59048b4813dae7c35 (patch)
treee88cd3fa666525fc8869679dce8335972d3bc9e2 /lib
parentadbf9a03518a94932e951c231852dffc63671432 (diff)
downloadyahns-392b42c68b2a2e4c5beb60f59048b4813dae7c35.tar.gz
This should make it easier to track state for asynchronous
proxy_pass buffering.
Diffstat (limited to 'lib')
-rw-r--r--lib/yahns/http_response.rb4
-rw-r--r--lib/yahns/wbuf.rb12
2 files changed, 9 insertions, 7 deletions
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