irc: shut down properly when the server does too
authorChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 1 Dec 2015 15:36:08 +0000 (09:36 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 1 Dec 2015 15:36:08 +0000 (09:36 -0600)
Formerly things would busyloop on irc disconnect; changed to prevent
that situation.

* 8sync/systems/irc.scm (make-basic-irc-handler): remove ports
  and don't break when the connection closes.

8sync/systems/irc.scm

index 1333c3c5868424a19f12ee1812c06063dfd3554a..80d4ce182f4fe2a7ba65aa729f56c63f0de3252c 100755 (executable)
     (define (reset-buffer)
       (set! buffer '()))
     (define (should-read-char socket)
-      (and (char-ready? socket) (not (eof-object? (peek-char socket)))))
+      (and (not (port-closed? socket))
+           (char-ready? socket)
+           (not (eof-object? (peek-char socket)))))
     (define (irc-handler socket)
       (while (should-read-char socket)
         (set! buffer (cons (read-char socket) buffer))
                           socket
                           ready-line
                           username))))
-          (_ #f))))
+          (_ #f)))
+      ;; I need to shut things down on EOF object
+      (cond
+       ((port-closed? socket)
+        (display "port closed time\n")
+        (port-remove-request socket))
+       ((and (char-ready? socket)
+             (eof-object? (peek-char socket)))
+        (display "port eof time\n")
+        (close socket)
+        (port-remove-request socket))))
     irc-handler))
 
 (define default-line-handler (make-handle-line))