Class: DTAS::UNIXClient
Overview
:nodoc:
Instance Attribute Summary collapse
-
#to_io ⇒ Object
readonly
Returns the value of attribute to_io.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path = self.class.default_path) ⇒ UNIXClient
constructor
A new instance of UNIXClient.
- #req(args, timeout = nil) ⇒ Object
- #req_ok(args, timeout = nil) ⇒ Object
- #req_start(args) ⇒ Object
- #res_wait(timeout = nil) ⇒ Object
Methods included from XS
Constructor Details
#initialize(path = self.class.default_path) ⇒ UNIXClient
Returns a new instance of UNIXClient.
19 20 21 22 |
# File 'lib/dtas/unix_client.rb', line 19 def initialize(path = self.class.default_path) @to_io = Socket.new(:UNIX, :SEQPACKET, 0) @to_io.connect(Socket.pack_sockaddr_un(path)) end |
Instance Attribute Details
#to_io ⇒ Object (readonly)
Returns the value of attribute to_io.
11 12 13 |
# File 'lib/dtas/unix_client.rb', line 11 def to_io @to_io end |
Class Method Details
.default_path ⇒ Object
15 16 17 |
# File 'lib/dtas/unix_client.rb', line 15 def self.default_path (ENV["DTAS_PLAYER_SOCK"] || File.("~/.dtas/player.sock")) end |
Instance Method Details
#req(args, timeout = nil) ⇒ Object
35 36 37 38 |
# File 'lib/dtas/unix_client.rb', line 35 def req(args, timeout = nil) req_start(args) res_wait(timeout) end |
#req_ok(args, timeout = nil) ⇒ Object
29 30 31 32 33 |
# File 'lib/dtas/unix_client.rb', line 29 def req_ok(args, timeout = nil) res = req(args, timeout) res == "OK" or raise "Unexpected response: #{res}" res end |
#req_start(args) ⇒ Object
24 25 26 27 |
# File 'lib/dtas/unix_client.rb', line 24 def req_start(args) args = xs(args) if Array === args @to_io.send(args, Socket::MSG_EOR) end |
#res_wait(timeout = nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/dtas/unix_client.rb', line 40 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 |