everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
blob a84eade7a2f2207df3590478a0c10a12f76d9a97 1552 bytes (raw)
name: lib/dtas/unix_accepted.rb 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
# 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'
require 'io/wait'

# an accepted (client) socket in dtas-player server
class DTAS::UNIXAccepted # :nodoc:
  attr_reader :to_io

  def initialize(sock)
    @to_io = sock
    @sbuf = []
  end

  # public API (for DTAS::Player)
  # returns :wait_readable on success
  def emit(msg)
    if @sbuf.empty?
      case rv = @to_io.sendmsg_nonblock(msg, Socket::MSG_EOR, exception: false)
      when :wait_writable
        @sbuf << msg
        rv
      else
        :wait_readable
      end
    else
      @sbuf << msg
      :wait_writable
    end
  rescue => e
    e
  end

  # flushes pending data if it got buffered
  def writable_iter
    case @to_io.sendmsg_nonblock(@sbuf[0], Socket::MSG_EOR, exception: false)
    when :wait_writable then return :wait_writable
    else
      @sbuf.shift
      @sbuf.empty? ? :wait_readable : :wait_writable
    end
  rescue => e
    e
  end

  def readable_iter
    nread = @to_io.nread

    # EOF, assume no spurious wakeups for SOCK_SEQPACKET
    return nil if nread == 0

    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
    @sbuf.empty? ? :wait_readable : :wait_writable
  rescue SystemCallError
    nil
  end

  def close
    @to_io.close
  end

  def closed?
    @to_io.closed?
  end
end

debug log:

solving a84eade ...
found a84eade in https://80x24.org/dtas.git/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).