From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 725BB1F852 for ; Sun, 23 Jan 2022 21:38:29 +0000 (UTC) Received: from localhost ([::1]:56492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nBkZA-0007UI-Ms for e@80x24.org; Sun, 23 Jan 2022 16:38:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBkZ9-0007TE-NF for dtas-all@nongnu.org; Sun, 23 Jan 2022 16:38:27 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:40094) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBkZ2-0000Av-4l for dtas-all@nongnu.org; Sun, 23 Jan 2022 16:38:21 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 200F71FA19 for ; Sun, 23 Jan 2022 21:37:47 +0000 (UTC) From: Eric Wong 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 Message-Id: <20220123213746.21085-8-e@80x24.org> In-Reply-To: <20220123213746.21085-1-e@80x24.org> References: <20220123213746.21085-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=64.71.152.64; envelope-from=e@80x24.org; helo=dcvr.yhbt.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: duct tape audio suite List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+e=80x24.org@nongnu.org Sender: "dtas-all" 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 +# Copyright (C) all contributors # License: GPL-3.0+ # 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 -# License: GPL-3.0+ - -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 +# Copyright (C) all contributors # License: GPL-3.0+ # 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 +# Copyright (C) all contributors # License: GPL-3.0+ # 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 +# Copyright (C) all contributors # License: GPL-3.0+ # 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 +# Copyright (C) all contributors # License: GPL-3.0+ # 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