]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Fix issue #101
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 28 Jun 2006 16:02:24 +0000 (16:02 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 28 Jun 2006 16:02:24 +0000 (16:02 +0000)
lib/rbot/ircbot.rb
lib/rbot/ircsocket.rb

index b2c7a88f91b4cef106066ed3946f831684e1bb67..51457a561dd24ae0ec554759b42ae495378ab904 100644 (file)
@@ -334,7 +334,7 @@ class IrcBot
         connect
         @timer.start
       
-        while true
+        while @socket.connected?
           if @socket.select
             break unless reply = @socket.gets
             @client.process reply
@@ -346,8 +346,10 @@ class IrcBot
       #rescue TimeoutError, SocketError => e
       rescue SystemExit
         exit 0
+      rescue TimeoutError => e
+        puts e
       rescue Exception => e
-        puts "network exception: connection closed: #{e.inspect}"
+        puts "network exception: #{e.inspect}"
         puts e.backtrace.join("\n")
         @socket.shutdown # now we reconnect
       rescue => e
@@ -613,10 +615,10 @@ class IrcBot
           debug "no PONG from server for #{diff} seconds, reconnecting"
           begin
             @socket.shutdown
-            # TODO
-            # raise an exception to get back to the mainloop
           rescue
             debug "couldn't shutdown connection (already shutdown?)"
+          ensure
+            raise TimeoutError, "no PONG from server in #{diff} seconds"
           end
           @last_ping = nil
         end
index 7b4175de55688938f6f6ff8528f0f53e95eae258..6ff93725b23fe2021d8daed67d33097a41081a3b 100644 (file)
@@ -49,9 +49,15 @@ module Irc
       end
     end
     
+    def connected?
+      !@sock.nil?
+    end
+
     # open a TCP connection to the server
     def connect
-      @sock = nil
+      if connected?
+       shutdown
+      end
       if(@host)
         begin
           @sock=TCPSocket.new(@server, @port, @host)