diff options
Diffstat (limited to 'lib/yahns/wbuf.rb')
-rw-r--r-- | lib/yahns/wbuf.rb | 12 |
1 files changed, 7 insertions, 5 deletions
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 |