diff options
author | Eric Wong <e@80x24.org> | 2013-11-01 22:01:45 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-11-01 22:01:45 +0000 |
commit | 98b663091a919035ea85bc5273bfe4bd1aac2073 (patch) | |
tree | a19b672ceea3f3594dd2c2cfed04b42f2c6aa210 | |
parent | 6f2f45e08e4142edbe83dcaba632773a94900d71 (diff) | |
download | yahns-98b663091a919035ea85bc5273bfe4bd1aac2073.tar.gz |
The first time we call wbuf_write, we do so because we already hit :wait_writable in the caller. So we can avoid the extra still-highly-likely-to-return-:wait_*) kgio_trywrite by writing to the VFS, first.
-rw-r--r-- | lib/yahns/wbuf.rb | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb index 10312db..8b2b82e 100644 --- a/lib/yahns/wbuf.rb +++ b/lib/yahns/wbuf.rb @@ -11,20 +11,19 @@ class Yahns::Wbuf # :nodoc: @sf_offset = @sf_count = 0 @wbuf_persist = persist # whether or not we keep the connection alive @body = body + @bypass = false 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 + case rv = client.kgio_trywrite(buf) + when String + buf = rv # retry in loop + 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 @sf_count += @tmpio.write(buf) case rv = client.trysendfile(@tmpio, @sf_offset, @sf_count) @@ -42,6 +41,7 @@ class Yahns::Wbuf # :nodoc: # to disk if we can help it. @tmpio.truncate(@sf_offset = 0) @tmpio.rewind + @bypass = true nil end |