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 045271F852 for ; Sun, 23 Jan 2022 21:38:35 +0000 (UTC) Received: from localhost ([::1]:56648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nBkZG-0007ag-9O for e@80x24.org; Sun, 23 Jan 2022 16:38:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBkZE-0007Yl-3M for dtas-all@nongnu.org; Sun, 23 Jan 2022 16:38:32 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:40200) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBkZC-0000Bg-Cr for dtas-all@nongnu.org; Sun, 23 Jan 2022 16:38:31 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3C0961FA1A for ; Sun, 23 Jan 2022 21:37:47 +0000 (UTC) From: Eric Wong To: dtas-all@nongnu.org Subject: [PATCH 8/9] unix_accepted: drop Ruby < 2.3 support code Date: Sun, 23 Jan 2022 21:37:45 +0000 Message-Id: <20220123213746.21085-9-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" This should save a little bit of memory for current users. --- lib/dtas/unix_accepted.rb | 49 ++++++++++----------------------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/lib/dtas/unix_accepted.rb b/lib/dtas/unix_accepted.rb index ec7f3ef..a84eade 100644 --- a/lib/dtas/unix_accepted.rb +++ b/lib/dtas/unix_accepted.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' @@ -10,23 +10,22 @@ class DTAS::UNIXAccepted # :nodoc: def initialize(sock) @to_io = sock - @send_buf = [] + @sbuf = [] end # public API (for DTAS::Player) # returns :wait_readable on success def emit(msg) - buffered = @send_buf.size - if buffered == 0 - case rv = sendmsg_nonblock(msg) + if @sbuf.empty? + case rv = @to_io.sendmsg_nonblock(msg, Socket::MSG_EOR, exception: false) when :wait_writable - @send_buf << msg + @sbuf << msg rv else :wait_readable end - else # buffered > 0 - @send_buf << msg + else + @sbuf << msg :wait_writable end rescue => e @@ -35,11 +34,11 @@ def emit(msg) # flushes pending data if it got buffered def writable_iter - case sendmsg_nonblock(@send_buf[0]) + case @to_io.sendmsg_nonblock(@sbuf[0], Socket::MSG_EOR, exception: false) when :wait_writable then return :wait_writable else - @send_buf.shift - @send_buf.empty? ? :wait_readable : :wait_writable + @sbuf.shift + @sbuf.empty? ? :wait_readable : :wait_writable end rescue => e e @@ -51,13 +50,13 @@ def readable_iter # EOF, assume no spurious wakeups for SOCK_SEQPACKET return nil if nread == 0 - case msg = recv_nonblock(nread) + case msg = @to_io.recv_nonblock(nread, exception: false) when :wait_readable then return msg when '', nil then return nil # EOF else yield(self, msg) # DTAS::Player deals with this end - @send_buf.empty? ? :wait_readable : :wait_writable + @sbuf.empty? ? :wait_readable : :wait_writable rescue SystemCallError nil end @@ -69,28 +68,4 @@ def close def closed? @to_io.closed? end - - if RUBY_VERSION.to_f >= 2.3 - def sendmsg_nonblock(msg) - @to_io.sendmsg_nonblock(msg, Socket::MSG_EOR, exception: false) - end - - def recv_nonblock(len) - @to_io.recv_nonblock(len, exception: false) - end - else - def sendmsg_nonblock(msg) - @to_io.sendmsg_nonblock(msg, Socket::MSG_EOR) - rescue IO::WaitWritable - :wait_writable - end - - def recv_nonblock(len) - @to_io.recv_nonblock(len) - rescue IO::WaitReadable - :wait_readable - rescue EOFError - nil - end - end end