about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-01-23 21:16:02 +0000
committerEric Wong <e@80x24.org>2022-01-23 21:16:47 +0000
commit773bfa23614aa483e590d635d732cc523fc38f37 (patch)
tree0f6b5c5b574b2b64648027521f05e15cb9c72734
parenteab2f44b4d02ee5e468a41d50275b6506adf83d6 (diff)
downloaddtas-773bfa23614aa483e590d635d732cc523fc38f37.tar.gz
get rid of DTAS::Nonblock wrapper for Ruby <= 2.0
We require 2.3+, nowadays, so jettison a bunch of code.
-rw-r--r--lib/dtas/buffer/read_write.rb3
-rw-r--r--lib/dtas/nonblock.rb24
-rw-r--r--lib/dtas/pipe.rb5
-rw-r--r--lib/dtas/process.rb5
-rw-r--r--lib/dtas/sigevent/fiddle_efd.rb3
-rw-r--r--lib/dtas/sigevent/pipe.rb5
-rw-r--r--lib/dtas/unix_server.rb16
-rw-r--r--lib/dtas/watchable.rb3
-rw-r--r--lib/dtas/watchable/fiddle_ino.rb2
9 files changed, 12 insertions, 54 deletions
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 'io/wait'
 require 'shellwords'
 require_relative '../dtas'
 require_relative 'xs'
-require_relative 'nonblock'
 
 # process management helpers
 module DTAS::Process # :nodoc:
@@ -88,12 +87,12 @@ module DTAS::Process # :nodoc:
       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 @@ class DTAS::UNIXServer # :nodoc:
 
   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 @@ class DTAS::UNIXServer # :nodoc:
       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