everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
blob 7382ea633c41ce58b734514577322eb0cb31c30b 1123 bytes (raw)
name: lib/dtas/unix_client.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
 
# Copyright (C) 2013-2014, Eric Wong <e@80x24.org> and all contributors
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require_relative '../dtas'
require_relative 'xs'
require 'socket'
require 'io/wait'
require 'shellwords'
require_relative 'compat_rbx'

class DTAS::UNIXClient # :nodoc:
  attr_reader :to_io

  include DTAS::XS

  def self.default_path
    (ENV["DTAS_PLAYER_SOCK"] || File.expand_path("~/.dtas/player.sock"))
  end

  def initialize(path = self.class.default_path)
    @to_io = Socket.new(:UNIX, :SEQPACKET, 0)
    @to_io.connect(Socket.pack_sockaddr_un(path))
  end

  def req_start(args)
    args = xs(args) if Array === args
    @to_io.send(args, Socket::MSG_EOR)
  end

  def req_ok(args, timeout = nil)
    res = req(args, timeout)
    res == "OK" or raise "Unexpected response: #{res}"
    res
  end

  def req(args, timeout = nil)
    req_start(args)
    res_wait(timeout)
  end

  def res_wait(timeout = nil)
    IO.select([@to_io], nil, nil, timeout)
    nr = @to_io.nread
    nr > 0 or raise EOFError, "unexpected EOF from server"
    @to_io.recvmsg(nr, 0, 0)[0]
  end
end

debug log:

solving 7382ea6 ...
found 7382ea6 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).