From: Eric Wong <e@80x24.org>
To: <dtas-all@nongnu.org>
Subject: [PATCH 1/2] use a common /dev/null
Date: Mon, 7 Sep 2015 21:40:33 +0000 [thread overview]
Message-ID: <20150907214034.28039-2-e@80x24.org> (raw)
In-Reply-To: <20150907214034.28039-1-e@80x24.org>
This allows us to avoid wasting time reopening the same
device over and over again.
---
lib/dtas.rb | 5 +++++
lib/dtas/buffer/splice.rb | 3 +--
lib/dtas/format.rb | 4 ++--
lib/dtas/player.rb | 2 +-
lib/dtas/sink.rb | 2 +-
5 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/lib/dtas.rb b/lib/dtas.rb
index f11d549..0b704ca 100644
--- a/lib/dtas.rb
+++ b/lib/dtas.rb
@@ -13,6 +13,11 @@ module DTAS # :nodoc:
Time.now.to_f
end
end
+
+ @null = nil
+ def self.null
+ @null ||= File.open('/dev/null', 'r+')
+ end
end
require_relative 'dtas/compat_onenine'
diff --git a/lib/dtas/buffer/splice.rb b/lib/dtas/buffer/splice.rb
index 02ce877..be40881 100644
--- a/lib/dtas/buffer/splice.rb
+++ b/lib/dtas/buffer/splice.rb
@@ -10,7 +10,6 @@ module DTAS::Buffer::Splice # :nodoc:
MAX_AT_ONCE = 4096 # page size in Linux
MAX_AT_ONCE_1 = 65536
MAX_SIZE = File.read("/proc/sys/fs/pipe-max-size").to_i
- DEVNULL = File.open("/dev/null", "r+")
F_MOVE = IO::Splice::F_MOVE
def buffer_size
@@ -25,7 +24,7 @@ module DTAS::Buffer::Splice # :nodoc:
# be sure to only call this with nil when all writers to @wr are done
def discard(bytes)
- IO.splice(@to_io, nil, DEVNULL, nil, bytes)
+ IO.splice(@to_io, nil, DTAS.null, nil, bytes)
end
def broadcast_one(targets, limit = nil)
diff --git a/lib/dtas/format.rb b/lib/dtas/format.rb
index a6314bd..cfcec64 100644
--- a/lib/dtas/format.rb
+++ b/lib/dtas/format.rb
@@ -44,9 +44,9 @@ class DTAS::Format # :nodoc:
def self.precision(env, infile)
# sox.git f4562efd0aa3
- qx(env, %W(soxi -p #{infile}), err: "/dev/null").to_i
+ qx(env, %W(soxi -p #{infile}), err: DTAS.null).to_i
rescue # fallback to parsing the whole output
- s = qx(env, %W(soxi #{infile}), err: "/dev/null")
+ s = qx(env, %W(soxi #{infile}), err: DTAS.null)
s =~ /Precision\s+:\s*(\d+)-bit/n
v = $1.to_i
return v if v > 0
diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb
index cdf1265..a102618 100644
--- a/lib/dtas/player.rb
+++ b/lib/dtas/player.rb
@@ -426,7 +426,7 @@ class DTAS::Player # :nodoc:
dst = @sink_buf
pending.dst_assoc(dst)
- pending.src_spawn(@format, @rg, out: dst.wr, in: "/dev/null")
+ pending.src_spawn(@format, @rg, out: dst.wr, in: DTAS.null)
# watch and restart on modifications
pending.respond_to?(:watch_begin) and
diff --git a/lib/dtas/sink.rb b/lib/dtas/sink.rb
index 70d6861..0bf49f4 100644
--- a/lib/dtas/sink.rb
+++ b/lib/dtas/sink.rb
@@ -91,7 +91,7 @@ class DTAS::Sink # :nodoc:
w.sink = self
rv << w
end
- opts[:in] = "/dev/null"
+ opts[:in] = DTAS.null
# map to real /dev/fd/* values and setup proper redirects
cmd = cmd.gsub(DEVFD_RE) do
--
EW
next prev parent reply other threads:[~2015-09-07 21:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-07 21:40 [PATCH 0/2] minor updates for readahead for -player Eric Wong
2015-09-07 21:40 ` Eric Wong [this message]
2015-09-07 21:40 ` [PATCH 2/2] player: add "queue cat" command Eric Wong
2015-09-20 23:02 ` [PATCH] dtas-readahead: new script for -player users on Linux Eric Wong
2015-10-03 9:38 ` [PATCH] dtas-readahead: make executable 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://80x24.org/dtas/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150907214034.28039-2-e@80x24.org \
--to=e@80x24.org \
--cc=dtas-all@nongnu.org \
/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://80x24.org/dtas.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).