lib/rmpd/connection.rb in rmpd-1.1.9 vs lib/rmpd/connection.rb in rmpd-1.1.11
- old
+ new
@@ -3,11 +3,10 @@
module Rmpd
class Connection
include Socket::Constants
include Rmpd::Commands
- include Rmpd::IO
MAX_RETRIES = 5
@@ -24,10 +23,28 @@
end
def connect
return unless @socket.nil? || @socket.closed?
+ if %r{^/} === @config.hostname
+ connect_unix_socket
+ else
+ connect_inet_socket
+ end
+
+ read_response # protocol version, ignore for now
+ password(@config.password) if @config.password
+ end
+
+ def connect_unix_socket
+ @socket = UNIXSocket.new(@config.hostname)
+ rescue StandardError => error
+ @socket = nil
+ raise MpdConnRefusedError.new(error)
+ end
+
+ def connect_inet_socket
Socket::getaddrinfo(@config.hostname, @config.port, nil, SOCK_STREAM).each do |info|
begin
sockaddr = Socket.pack_sockaddr_in(info[1], info[3])
@socket = Socket.new(info[4], info[5], 0)
@socket.connect(sockaddr)
@@ -36,12 +53,9 @@
raise MpdConnRefusedError.new(error)
else
break
end
end
-
- read_response # protocol version, ignore for now
- password(@config.password) if @config.password
end
def send_command(command, *args)
tries = 0