X-Git-Url: http://dolda2000.com/gitweb/?p=lisp-utils.git;a=blobdiff_plain;f=mpcl.lisp;h=de3e41012501aa1eae32ce3c1455b5dfc855eeb9;hp=4cc6656a0a9740c5a7aaa53507477fa22b39bacf;hb=b466cd484e1cf6b7c7a0d2fdb791a3cf40560f46;hpb=9d561d5d6bc68bb900271677cfc5e2b7e191eac3 diff --git a/mpcl.lisp b/mpcl.lisp index 4cc6656..de3e410 100644 --- a/mpcl.lisp +++ b/mpcl.lisp @@ -153,7 +153,9 @@ "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) @@ -192,7 +194,19 @@ :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