[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/9] get rid of DTAS::Nonblock wrapper for Ruby <= 2.0
From: |
Eric Wong |
Subject: |
[PATCH 7/9] get rid of DTAS::Nonblock wrapper for Ruby <= 2.0 |
Date: |
Sun, 23 Jan 2022 21:37:44 +0000 |
We require 2.3+, nowadays, so jettison a bunch of code.
---
lib/dtas/buffer/read_write.rb | 3 +--
lib/dtas/nonblock.rb | 24 ------------------------
lib/dtas/pipe.rb | 5 ++---
lib/dtas/process.rb | 5 ++---
lib/dtas/sigevent/fiddle_efd.rb | 3 +--
lib/dtas/sigevent/pipe.rb | 5 ++---
lib/dtas/unix_server.rb | 16 ++--------------
lib/dtas/watchable.rb | 3 +--
lib/dtas/watchable/fiddle_ino.rb | 2 +-
9 files changed, 12 insertions(+), 54 deletions(-)
delete mode 100644 lib/dtas/nonblock.rb
diff --git a/lib/dtas/buffer/read_write.rb b/lib/dtas/buffer/read_write.rb
index fdf820c..8fdb25d 100644
--- a/lib/dtas/buffer/read_write.rb
+++ b/lib/dtas/buffer/read_write.rb
@@ -1,10 +1,9 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
require 'io/nonblock'
require_relative '../../dtas'
require_relative '../pipe'
-require_relative '../nonblock'
# compatibility code for non-Linux systems lacking "splice" support.
# Used only by -player
diff --git a/lib/dtas/nonblock.rb b/lib/dtas/nonblock.rb
deleted file mode 100644
index 2cf086c..0000000
--- a/lib/dtas/nonblock.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright (C) 2015-2020 all contributors <dtas-all@nongnu.org>
-# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
-
-class DTAS::Nonblock < IO # :nodoc:
- if RUBY_VERSION.to_f <= 2.0
- EX = {}.freeze
- def read_nonblock(len, buf = nil, opts = EX)
- super(len, buf)
- rescue IO::WaitReadable
- raise if opts[:exception]
- :wait_readable
- rescue EOFError
- raise if opts[:exception]
- nil
- end
-
- def write_nonblock(buf, opts = EX)
- super(buf)
- rescue IO::WaitWritable
- raise if opts[:exception]
- :wait_writable
- end
- end
-end
diff --git a/lib/dtas/pipe.rb b/lib/dtas/pipe.rb
index 34d50bd..a7b02b0 100644
--- a/lib/dtas/pipe.rb
+++ b/lib/dtas/pipe.rb
@@ -1,12 +1,11 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
require_relative '../dtas'
require_relative 'writable_iter'
-require_relative 'nonblock'
# pipe wrapper for -player sinks
-class DTAS::Pipe < DTAS::Nonblock # :nodoc:
+class DTAS::Pipe < IO # :nodoc:
include DTAS::WritableIter
attr_accessor :sink
diff --git a/lib/dtas/process.rb b/lib/dtas/process.rb
index d00716f..02bf77e 100644
--- a/lib/dtas/process.rb
+++ b/lib/dtas/process.rb
@@ -5,7 +5,6 @@
require 'shellwords'
require_relative '../dtas'
require_relative 'xs'
-require_relative 'nonblock'
# process management helpers
module DTAS::Process # :nodoc:
@@ -88,12 +87,12 @@ def qx(env, cmd = {}, opts = {})
env = {}
end
buf = ''.b
- r, w = DTAS::Nonblock.pipe
+ r, w = IO.pipe
opts = opts.merge(out: w)
r.binmode
no_raise = opts.delete(:no_raise)
if err_str = opts.delete(:err_str)
- re, we = DTAS::Nonblock.pipe
+ re, we = IO.pipe
re.binmode
opts[:err] = we
end
diff --git a/lib/dtas/sigevent/fiddle_efd.rb b/lib/dtas/sigevent/fiddle_efd.rb
index ec9ec65..8bfa332 100644
--- a/lib/dtas/sigevent/fiddle_efd.rb
+++ b/lib/dtas/sigevent/fiddle_efd.rb
@@ -4,7 +4,6 @@
# used in various places for safe wakeups from IO.select via signals
# This requires a modern GNU/Linux system with eventfd(2) support
-require_relative '../nonblock'
require 'fiddle'
class DTAS::Sigevent # :nodoc:
@@ -18,7 +17,7 @@ class DTAS::Sigevent # :nodoc:
def initialize
fd = EventFD.call(0, 02000000|00004000) # EFD_CLOEXEC|EFD_NONBLOCK
raise "eventfd failed: #{Fiddle.last_error}" if fd < 0
- @to_io = DTAS::Nonblock.for_fd(fd)
+ @to_io = IO.for_fd(fd)
@buf = ''.b
end
diff --git a/lib/dtas/sigevent/pipe.rb b/lib/dtas/sigevent/pipe.rb
index e6fbbf2..6c3b83c 100644
--- a/lib/dtas/sigevent/pipe.rb
+++ b/lib/dtas/sigevent/pipe.rb
@@ -1,15 +1,14 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
# used in various places for safe wakeups from IO.select via signals
# A fallback for non-Linux systems lacking the "splice" syscall
-require_relative '../nonblock'
class DTAS::Sigevent # :nodoc:
attr_reader :to_io
def initialize
- @to_io, @wr = DTAS::Nonblock.pipe
+ @to_io, @wr = IO.pipe
@rbuf = ''.b
end
diff --git a/lib/dtas/unix_server.rb b/lib/dtas/unix_server.rb
index cad3fc4..60ab86c 100644
--- a/lib/dtas/unix_server.rb
+++ b/lib/dtas/unix_server.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
require 'socket'
@@ -59,7 +59,7 @@ def write_failed(client, e)
def readable_iter
# we do not do anything with the block passed to us
- case rv = accept_nonblock
+ case rv = @to_io.accept_nonblock(exception: false)
when :wait_readable then return rv
else
@readers[DTAS::UNIXAccepted.new(rv[0])] = true
@@ -114,16 +114,4 @@ def run_once
wait_ctl(io, io.readable_iter { |_io, msg| yield(_io, msg) })
end
end
-
- if RUBY_VERSION.to_f >= 2.3
- def accept_nonblock
- @to_io.accept_nonblock(exception: false)
- end
- else
- def accept_nonblock
- @to_io.accept_nonblock
- rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO
- :wait_readable
- end
- end
end
diff --git a/lib/dtas/watchable.rb b/lib/dtas/watchable.rb
index 6168bf3..445bf98 100644
--- a/lib/dtas/watchable.rb
+++ b/lib/dtas/watchable.rb
@@ -1,8 +1,7 @@
-# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
require_relative '../dtas'
-require_relative 'nonblock'
begin
module DTAS::Watchable # :nodoc:
module InotifyCommon # :nodoc:
diff --git a/lib/dtas/watchable/fiddle_ino.rb b/lib/dtas/watchable/fiddle_ino.rb
index b24bbf6..3ec72a1 100644
--- a/lib/dtas/watchable/fiddle_ino.rb
+++ b/lib/dtas/watchable/fiddle_ino.rb
@@ -22,7 +22,7 @@ class DTAS::Watchable::InotifyReadableIter # :nodoc:
def initialize # :nodoc:
fd = Inotify_init.call(02000000 | 04000) # CLOEXEC | NONBLOCK
raise "inotify_init failed: #{Fiddle.last_error}" if fd < 0
- @to_io = DTAS::Nonblock.for_fd(fd)
+ @to_io = IO.for_fd(fd)
@buf = ''.b
@q = []
end
- [PATCH 0/9] various cuts for memory savings, Eric Wong, 2022/01/23
- [PATCH 1/9] deduplicate and freeze pathnames + metadata, Eric Wong, 2022/01/23
- [PATCH 2/9] player: remove omap conversion, Eric Wong, 2022/01/23
- [PATCH 3/9] dtas: drop unnecessary "require 'yaml'" statements, Eric Wong, 2022/01/23
- [PATCH 4/9] dtas-tl prune: cull missing files from tracklist, Eric Wong, 2022/01/23
- [PATCH 5/9] dtas-tl: drop encoding hacks, use binary stdout+stderr, Eric Wong, 2022/01/23
- [PATCH 6/9] use IO#wait_readable consistently, Eric Wong, 2022/01/23
- [PATCH 7/9] get rid of DTAS::Nonblock wrapper for Ruby <= 2.0,
Eric Wong <=
- [PATCH 8/9] unix_accepted: drop Ruby < 2.3 support code, Eric Wong, 2022/01/23
- [PATCH 9/9] do not check IO#closed? before calling IO#close, Eric Wong, 2022/01/23