mpc.lua: Add support for Unix sockets (#115)
If the host name begins with a slash then we assume that it is a unix socket. Else, we use a TCP connection as before. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
46c310f8da
commit
71791fbfb5
|
@ -50,9 +50,17 @@ function mpc:_connect()
|
|||
self._idle = false
|
||||
self._connected = true
|
||||
|
||||
-- Set up a new TCP connection
|
||||
-- Set up a new connection
|
||||
local address
|
||||
if string.sub(self._host, 1, 1) == "/" then
|
||||
-- It's a unix socket
|
||||
address = Gio.UnixSocketAddress.new(self._host)
|
||||
else
|
||||
-- Do a TCP connection
|
||||
address = Gio.NetworkAddress.new(self._host, self._port)
|
||||
end
|
||||
local client = Gio.SocketClient()
|
||||
local conn, err = client:connect_to_host(self._host, self._port)
|
||||
local conn, err = client:connect(address)
|
||||
|
||||
if not conn then
|
||||
self:_error(err)
|
||||
|
|
Loading…
Reference in New Issue