COMMON-NET: Added a couple of functions for parsing/formatting DNs.
[lisp-utils.git] / mpcl.lisp
index 4cc6656..de3e410 100644 (file)
--- a/mpcl.lisp
+++ b/mpcl.lisp
   "Disconnect from MPD."
   (with-conn-lock
     (let ((sk (prog1 *socket* (setf *socket* nil))))
-      (if sk (ignore-errors (close sk))))))
+      (when sk (handler-case
+                  (close sk)
+                (error () (close sk :abort t)))))))
 
 (defun connection-error (condition-type &rest condition-args)
   (disconnect)
                                 :message "Invalid response from mpd: ~A"
                                 :inputs (list line))))))))
 
-(defun connect (&key (host "localhost") (port 6600))
+(defun default-host ()
+  (block nil
+    #+sbcl (let ((host (sb-posix:getenv "MPD_HOST")))
+            (when host (return host)))
+    "localhost"))
+
+(defun default-port ()
+  (block nil
+    #+sbcl (let ((port (sb-posix:getenv "MPD_PORT")))
+            (when port (return (parse-integer port))))
+    6600))
+
+(defun connect (&key (host (default-host)) (port (default-port)))
   "Connect to a running MPD."
   (disconnect)
   (with-conn-lock