everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: dtas-all@nongnu.org
Subject: [PATCH 7/9] get rid of DTAS::Nonblock wrapper for Ruby <= 2.0
Date: Sun, 23 Jan 2022 21:37:44 +0000	[thread overview]
Message-ID: <20220123213746.21085-8-e@80x24.org> (raw)
In-Reply-To: <20220123213746.21085-1-e@80x24.org>

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


  parent reply	other threads:[~2022-01-23 21:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-23 21:37 [PATCH 0/9] various cuts for memory savings Eric Wong
2022-01-23 21:37 ` [PATCH 1/9] deduplicate and freeze pathnames + metadata Eric Wong
2022-01-23 21:37 ` [PATCH 2/9] player: remove omap conversion Eric Wong
2022-01-23 21:37 ` [PATCH 3/9] dtas: drop unnecessary "require 'yaml'" statements Eric Wong
2022-01-23 21:37 ` [PATCH 4/9] dtas-tl prune: cull missing files from tracklist Eric Wong
2022-01-23 21:37 ` [PATCH 5/9] dtas-tl: drop encoding hacks, use binary stdout+stderr Eric Wong
2022-01-23 21:37 ` [PATCH 6/9] use IO#wait_readable consistently Eric Wong
2022-01-23 21:37 ` Eric Wong [this message]
2022-01-23 21:37 ` [PATCH 8/9] unix_accepted: drop Ruby < 2.3 support code Eric Wong
2022-01-23 21:37 ` [PATCH 9/9] do not check IO#closed? before calling IO#close 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=20220123213746.21085-8-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).