]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Loop until connected in reconnect()
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 20 Oct 2009 18:22:22 +0000 (20:22 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 21 Oct 2009 16:59:21 +0000 (18:59 +0200)
Untrapped connect() failures would raise up to the mainloop, causing a
burst of reconnect attempts without delay. Fix by rescuing in
reconnect() and retrying after waiting.

lib/rbot/ircbot.rb

index 2f146c2936b8cf1e1ce348d465e1012c790d5dbb..6f7bed7de8e194c012d61fc1a58ed38dfec780ae 100644 (file)
@@ -940,17 +940,22 @@ class Bot
       disconnect(message)
     end
 
-    if will_wait
-      log "\n\nDisconnected\n\n"
+    begin
+      if will_wait
+        log "\n\nDisconnected\n\n"
 
-      quit if $interrupted > 0
+        quit if $interrupted > 0
 
-      log "\n\nWaiting to reconnect\n\n"
-      sleep @config['server.reconnect_wait']
-      sleep 10*@config['server.reconnect_wait'] if too_fast
-    end
+        log "\n\nWaiting to reconnect\n\n"
+        sleep @config['server.reconnect_wait']
+        sleep 10*@config['server.reconnect_wait'] if too_fast
+      end
 
-    connect
+      connect
+    rescue Exception => e
+      will_wait = true
+      retry
+    end
   end
 
   # begin event handling loop