summary refs log tree commit diff
path: root/guix/avahi.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/avahi.scm')
-rw-r--r--guix/avahi.scm30
1 files changed, 21 insertions, 9 deletions
diff --git a/guix/avahi.scm b/guix/avahi.scm
index 132e42f268..574fe0b850 100644
--- a/guix/avahi.scm
+++ b/guix/avahi.scm
@@ -49,11 +49,17 @@
   (port avahi-service-port)
   (txt avahi-service-txt))
 
+(define never
+  ;; Never true.
+  (const #f))
+
 (define* (avahi-publish-service-thread name
                                        #:key
                                        type port
-                                       (stop-loop? (const #f))
-                                       (timeout 100)
+                                       (stop-loop? never)
+                                       (timeout (if (eq? stop-loop? never)
+                                                    #f
+                                                    500))
                                        (txt '()))
   "Publish the service TYPE using Avahi, for the given PORT, on all interfaces
 and for all protocols. Also, advertise the given TXT record list.
@@ -78,7 +84,9 @@ when STOP-LOOP? procedure returns true."
                                   client-flag/ignore-user-config)
                                  client-callback)))
        (while (not (stop-loop?))
-         (iterate-simple-poll poll timeout))))))
+         (if timeout
+             (iterate-simple-poll poll timeout)
+             (iterate-simple-poll poll)))))))
 
 (define (interface->ip-address interface)
   "Return the local IP address of the given INTERFACE."
@@ -89,10 +97,6 @@ when STOP-LOOP? procedure returns true."
     (close-port socket)
     ip))
 
-(define never
-  ;; Never true.
-  (const #f))
-
 (define* (avahi-browse-service-thread proc
                                       #:key
                                       types
@@ -101,7 +105,7 @@ when STOP-LOOP? procedure returns true."
                                       (stop-loop? never)
                                       (timeout (if (eq? stop-loop? never)
                                                    #f
-                                                   100)))
+                                                   500)))
   "Browse services which type is part of the TYPES list, using Avahi.  The
 search is restricted to services with the given FAMILY.  Each time a service
 is found or removed, PROC is called and passed as argument the corresponding
@@ -137,7 +141,15 @@ when STOP-LOOP? procedure returns true."
                                (port port)
                                (txt txt))))
                (hash-set! %known-hosts service-name service*)
-               (proc 'new-service service*)))))
+               (proc 'new-service service*))))
+          ((eq? event resolver-event/failure)
+           ;; Failure to resolve the host associated with a service.  This
+           ;; usually means that the mDNS record hasn't expired yet but that
+           ;; the host went off-line.
+           (let ((service (hash-ref %known-hosts service-name)))
+             (when service
+               (proc 'remove-service service)
+               (hash-remove! %known-hosts service-name)))))
     (free-service-resolver! resolver))
 
   (define (service-browser-callback browser interface protocol event