Moved char2hex to misc.lsp.
[rrq/lsp-utils.git] / lsp-dbus / lsp-dbus-connection.lsp
index 3ac9b068a6db20a04775725d54ec9d0b835be6d0..73e96728f3581f577c23953f368ec82219f9ea74 100644 (file)
 
 (define (read-message)
   (let ((BUFFER "") (RESULT ""))
-    (while (net-select (%socket) "r" 1000)
-      (net-receive (%socket) BUFFER 8192)
-      (extend RESULT BUFFER))
+    (while (and RESULT (net-select (%socket) "r" 1000))
+      (if (net-receive (%socket) BUFFER 8192)
+          (extend RESULT BUFFER)
+        (begin
+          (setf RESULT nil)
+          (die 1 "dbus socket closed"))
+        ))
     RESULT))
 
 ;; (handshake MSG PAT)
@@ -54,9 +58,6 @@
     (setf RESULT (read-message))
     (if PAT (regex PAT RESULT 0) RESULT)))
 
-(define (char2hex STR)
-  (join (map (curry format "%2x") (map char (explode STR)))))
-
 (constant
  'AUTHFMT "AUTH EXTERNAL %s\r\n"
  'AUTHACK "OK (\\S+)\r\n"
@@ -78,5 +79,4 @@
 (define (cancel)
   (handshake "CANCEL\r\n" "(.*)"))
 
-"DbusConnection"
-
+"lsp-dbus-connection.lsp"