Skip to content

Connect over unix domain socket #4

@winny-

Description

@winny-

My first thought was to allow port be nil which would indicate a unix domain socket via (make-network-process :service (expand-file-name host) :family 'local :name "mpd"), but this would most likely not work in all situations; chiefly, when MPD_HOST is set to a file path, and somehow MPD_PORT is set as well, other MPD clients will correctly connect to the unix socket, despite the port being set as an env variable. (Tested with mpc, ncmpc, ncmpcc.)

So maybe the best route will be to test if host is a path (look for the filesystem's path separator) and simply ignore port if a path separator one exists in host.

Below is a PoC patch which I found to be in the right direction, but not really suitable as per what I stated above:

diff --git a/libmpdee.el b/libmpdee.el
index 86158f6..f9a1763 100644
--- a/libmpdee.el
+++ b/libmpdee.el
@@ -479,7 +479,7 @@ before giving up waiting for a reply from the server. Unspecified or zero
 TIMEOUT correspond to infinite timeout. Set automatic mode if NOAUTO is nil,
 hooked automatic function if NOAUTO is a function, and do not set automatic mode
 otherwise. See `mpd-set-automatic-mode' for a description of automatic mode."
-  (or (and (stringp host) (wholenump port) (or (not timeout) (numberp timeout)))
+  (or (and (stringp host) (or (wholenump port) (not port)) (or (not timeout) (numberp timeout)))
       (error "Invalid parameters passed for making new connection"))
   (and timeout
        (if (= timeout 0)
@@ -502,7 +502,9 @@ function doesn't need to be explicitly called when the connection is in
 automatic mode (the default). Close the connection using `mpd-close-connection'
 when you are done."
   (let (proc rt welc)
-    (setq proc (or (open-network-stream "mpd" nil (_mpdgh) (_mpdgp))
+    (setq proc (or (if (_mpdgp)
+                       (open-network-stream "mpd" nil (_mpdgh) (_mpdgp))
+                     (make-network-process :name "mpd" :service (expand-file-name (_mpdgh)) :family 'local))
                   (error "Unable to open connection with mpd")))
     (and (_mpdgo) (delete-process (_mpdgo)))
     (_mpdso proc)

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions