From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] allow vector args to wbuf_write
Date: Fri, 3 Apr 2015 01:53:29 +0000 [thread overview]
Message-ID: <1428026009-23379-1-git-send-email-e@80x24.org> (raw)
This allows us to write chunked response bodies without extra
copying to clients which support streaming.
---
lib/yahns/wbuf.rb | 16 ++++++++++------
1 file 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 @@ def initialize(body, persist, tmpdir, busy)
@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 @@ def wbuf_write(client, buf)
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
--
EW
reply other threads:[~2015-04-03 1:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/yahns/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1428026009-23379-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=yahns-public@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).