irc: Avoid connecting to #f socket, attempt reconnect.
[8sync.git] / 8sync / systems / irc.scm
index aa43624389bd0705acf3827c689e34830fde158c..0007de8499748d5c3ae73b806f521a8a6247eed5 100644 (file)
   (let* ((s (socket PF_INET SOCK_STREAM 0))
          (flags (fcntl s F_GETFL))
          (ip-address (inet-ntop AF_INET (car (hostent:addr-list (gethost hostname))))))
-    (fcntl s F_SETFL (logior O_NONBLOCK flags))
-    (connect s AF_INET
-             (inet-pton AF_INET ip-address)
-             inet-port)
-    s))
+    (cond (s
+           (fcntl s F_SETFL (logior O_NONBLOCK flags))
+           (connect s AF_INET (inet-pton AF_INET ip-address) inet-port)
+           s)
+          (else
+           (8sleep 1)
+           (irc-socket-setup hostname inet-port)))))
 
 (define irc-eol "\r\n")