From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] wbuf: lazily (re)create temporary file
Date: Sat, 24 Jan 2015 00:25:28 +0000 [thread overview]
Message-ID: <1422059128-3998-2-git-send-email-e@80x24.org> (raw)
We may not need this temporary file if we've flushed everything
out and entered bypass mode.
---
lib/yahns/wbuf.rb | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb
index 991557e..4eed2c5 100644
--- a/lib/yahns/wbuf.rb
+++ b/lib/yahns/wbuf.rb
@@ -1,5 +1,5 @@
# -*- encoding: binary -*-
-# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> et. al.
+# Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require_relative 'wbuf_common'
@@ -31,7 +31,7 @@ class Yahns::Wbuf # :nodoc:
include Yahns::WbufCommon
def initialize(body, persist, tmpdir)
- @tmpio = Yahns::TmpIO.new(tmpdir)
+ @tmpio = nil
@tmpdir = tmpdir
@sf_offset = @sf_count = 0
@wbuf_persist = persist # whether or not we keep the connection alive
@@ -50,6 +50,7 @@ def wbuf_write(client, buf)
@bypass = false # ugh, continue to buffering to file
end while @bypass
+ @tmpio ||= Yahns::TmpIO.new(@tmpdir)
@sf_count += @tmpio.write(buf)
case rv = client.trysendfile(@tmpio, @sf_offset, @sf_count)
when Integer
@@ -64,16 +65,15 @@ def wbuf_write(client, buf)
# we're all caught up, try to prevent dirty data from getting flushed
# to disk if we can help it.
- @tmpio.close
+ @tmpio = @tmpio.close
@sf_offset = 0
- @tmpio = Yahns::TmpIO.new(@tmpdir)
@bypass = true
nil
end
# called by last wbuf_flush
def wbuf_close(client)
- @tmpio = @tmpio.close
+ @tmpio = @tmpio.close if @tmpio
wbuf_close_common(client)
end
end
--
EW
reply other threads:[~2015-01-24 0:25 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: http://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=1422059128-3998-2-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
http://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).