From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH 1/2] wbuf: remove tmpdir parameter
Date: Mon, 6 Jun 2016 05:14:20 +0000 [thread overview]
Message-ID: <20160606051421.7082-2-e@80x24.org> (raw)
In-Reply-To: <20160606051421.7082-1-e@80x24.org>
We can retrieve it when we actually need to create the
temporary file. This saves an ivar slot and method dispatch
parameters.
This patch is nice, unfortunately the patch which follows is
not :P
---
lib/yahns/http_response.rb | 4 ++--
lib/yahns/proxy_http_response.rb | 2 +-
lib/yahns/wbuf.rb | 5 ++---
test/test_wbuf.rb | 9 ++++++---
4 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb
index 531194f..d957df6 100644
--- a/lib/yahns/http_response.rb
+++ b/lib/yahns/http_response.rb
@@ -62,7 +62,7 @@ def response_header_blocked(header, body, alive, offset, count)
alive = Yahns::StreamFile.new(body, alive, offset, count)
body = nil
end
- wbuf = Yahns::Wbuf.new(body, alive, self.class.output_buffer_tmpdir)
+ wbuf = Yahns::Wbuf.new(body, alive)
rv = wbuf.wbuf_write(self, header)
if body && ! alive.respond_to?(:call) # skip body.each if hijacked
body.each { |chunk| rv = wbuf.wbuf_write(self, chunk) }
@@ -199,7 +199,7 @@ def http_response_write(status, headers, body)
chunk = rv # hope the skb grows when we loop into the trywrite
when :wait_writable, :wait_readable
if k.output_buffering
- wbuf = Yahns::Wbuf.new(body, alive, k.output_buffer_tmpdir)
+ wbuf = Yahns::Wbuf.new(body, alive)
rv = wbuf.wbuf_write(self, chunk)
break
else
diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb
index 61f1539..8de5b4f 100644
--- a/lib/yahns/proxy_http_response.rb
+++ b/lib/yahns/proxy_http_response.rb
@@ -21,7 +21,7 @@ def proxy_unbuffer(wbuf)
def wbuf_alloc(req_res)
if req_res.proxy_pass.proxy_buffering
- Yahns::Wbuf.new(nil, req_res.alive, self.class.output_buffer_tmpdir)
+ Yahns::Wbuf.new(nil, req_res.alive)
else
Yahns::WbufLite.new(req_res)
end
diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb
index 1010c86..583df10 100644
--- a/lib/yahns/wbuf.rb
+++ b/lib/yahns/wbuf.rb
@@ -32,9 +32,8 @@ class Yahns::Wbuf # :nodoc:
include Yahns::WbufCommon
attr_reader :busy
- def initialize(body, persist, tmpdir)
+ def initialize(body, persist)
@tmpio = nil
- @tmpdir = tmpdir
@sf_offset = @sf_count = 0
@wbuf_persist = persist # whether or not we keep the connection alive
@body = body # something we call #close on when done writing
@@ -58,7 +57,7 @@ def wbuf_write(c, buf)
@busy = rv
end until @busy
- @tmpio ||= Yahns::TmpIO.new(@tmpdir)
+ @tmpio ||= Yahns::TmpIO.new(c.class.output_buffer_tmpdir)
@sf_count += String === buf ? @tmpio.write(buf) : wbuf_writev(buf)
# we spent some time copying to the FS, try to write to
diff --git a/test/test_wbuf.rb b/test/test_wbuf.rb
index 990ad9d..1382086 100644
--- a/test/test_wbuf.rb
+++ b/test/test_wbuf.rb
@@ -9,6 +9,9 @@ class TestWbuf < Testcase
class KgioUS < UNIXSocket
include Kgio::SocketMethods
+ def self.output_buffer_tmpdir
+ Dir.tmpdir
+ end
end
def socketpair
@@ -20,7 +23,7 @@ def test_wbuf
buf = "*" * (16384 * 2)
nr = 1000
[ true, false ].each do |persist|
- wbuf = Yahns::Wbuf.new([], persist, Dir.tmpdir)
+ wbuf = Yahns::Wbuf.new([], persist)
assert_equal false, wbuf.busy
a, b = socketpair
assert_nil wbuf.wbuf_write(a, "HIHI")
@@ -71,7 +74,7 @@ def test_wbuf_blocked
break
end while true
end
- wbuf = Yahns::Wbuf.new([], true, Dir.tmpdir)
+ wbuf = Yahns::Wbuf.new([], true)
rv1 = wbuf.wbuf_write(a, buf)
rv2 = wbuf.wbuf_flush(a)
@@ -104,7 +107,7 @@ def test_wbuf_blocked
def test_wbuf_flush_close
pipe = cloexec_pipe
persist = true
- wbuf = Yahns::Wbuf.new(pipe[0], persist, Dir.tmpdir)
+ wbuf = Yahns::Wbuf.new(pipe[0], persist)
refute wbuf.respond_to?(:close) # we don't want this for HttpResponse body
sp = socketpair
rv = nil
next prev parent reply other threads:[~2016-06-06 5:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-06 5:14 [YUCK 0/2] wbuf_lite: fix write retries for OpenSSL Eric Wong
2016-06-06 5:14 ` Eric Wong [this message]
2016-06-06 5:14 ` [PATCH 2/2] wbuf_lite: fix write retries for OpenSSL sockets Eric Wong
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=20160606051421.7082-2-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).