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 8/9] unix_accepted: drop Ruby < 2.3 support code
Date: Sun, 23 Jan 2022 21:37:45 +0000	[thread overview]
Message-ID: <20220123213746.21085-9-e@80x24.org> (raw)
In-Reply-To: <20220123213746.21085-1-e@80x24.org>

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 <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'
@@ -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


  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 ` [PATCH 7/9] get rid of DTAS::Nonblock wrapper for Ruby <= 2.0 Eric Wong
2022-01-23 21:37 ` Eric Wong [this message]
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: http://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-9-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

	http://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).