about summary refs log tree commit homepage
path: root/lib/yahns/wbuf.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-11-01 10:50:38 +0000
committerEric Wong <normalperson@yhbt.net>2013-11-01 10:50:38 +0000
commit4d3fe8b58e707670ba40dda83ec460adca0596a3 (patch)
treef725fee22388fb3ed6ed4a600e8cba82e216bb57 /lib/yahns/wbuf.rb
parent93ba820f05aaf8c760b4a515ae996425c257a7fb (diff)
downloadyahns-4d3fe8b58e707670ba40dda83ec460adca0596a3.tar.gz
Sometimes buffering can catch up and we no longer need to
use the on-disk buffer, so keep trying to flush the data
out to the user to avoid VFS activity.
Diffstat (limited to 'lib/yahns/wbuf.rb')
-rw-r--r--lib/yahns/wbuf.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb
index 4828056..df7d56d 100644
--- a/lib/yahns/wbuf.rb
+++ b/lib/yahns/wbuf.rb
@@ -14,6 +14,18 @@ class Yahns::Wbuf # :nodoc:
   end
 
   def wbuf_write(client, buf)
+    # try to bypass the VFS layer if we're all caught up
+    if @sf_count == 0
+      case rv = client.kgio_trywrite(buf)
+      when String
+        buf = rv # retry in loop
+      when nil
+        return nil # yay! hopefully we don't have to buffer again
+      when :wait_writable, :wait_readable
+        break # ugh, continue to buffering to file
+      end while true
+    end
+
     @sf_count += @tmpio.write(buf)
     case rv = client.trysendfile(@tmpio, @sf_offset, @sf_count)
     when Integer