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:27 +0000
committerEric Wong <e@80x24.org>2015-04-03 00:14:43 +0000
commit44e533af884bcebd38a319287f359cbfbc161b55 (patch)
tree4a7ecfcc6980c83fc51a35e6207c283146bc1fd8 /lib
parentdcdc62ee5fc8d7721df3d9bbdbce88bedf87cc16 (diff)
downloadyahns-44e533af884bcebd38a319287f359cbfbc161b55.tar.gz
This allows us to write chunked response bodies without extra
copying to clients which support streaming.
Diffstat (limited to 'lib')
-rw-r--r--lib/yahns/wbuf.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb
index ba7ea0f..fa39b9b 100644
--- a/lib/yahns/wbuf.rb
+++ b/lib/yahns/wbuf.rb
@@ -40,10 +40,11 @@ class Yahns::Wbuf # :nodoc:
     @busy = busy # may be false
   end
 
-  def wbuf_write(client, buf)
-    # try to bypass the VFS layer if we're all caught up
-    case rv = client.kgio_trywrite(buf)
-    when String
+  def wbuf_write(c, buf)
+    # try to bypass the VFS layer and write directly to the socket
+    # if we're all caught up
+    case rv = String === buf ? c.kgio_trywrite(buf) : c.kgio_trywritev(buf)
+    when String, Array
       buf = rv # retry in loop
     when nil
       return # yay! hopefully we don't have to buffer again
@@ -52,8 +53,11 @@ class Yahns::Wbuf # :nodoc:
     end until @busy
 
     @tmpio ||= Yahns::TmpIO.new(@tmpdir)
-    @sf_count += @tmpio.write(buf)
-    case rv = client.trysendfile(@tmpio, @sf_offset, @sf_count)
+    @sf_count += String === buf ? @tmpio.write(buf) : @tmpio.kgio_writev(buf)
+
+    # we spent some time copying to the FS, try to write to
+    # the socket again in case some space opened up...
+    case rv = c.trysendfile(@tmpio, @sf_offset, @sf_count)
     when Integer
       @sf_count -= rv
       @sf_offset += rv