From d764894efae89970e22bad48db4c76d878b35630 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 28 Jun 2006 16:02:24 +0000 Subject: Fix issue #101 --- lib/rbot/ircbot.rb | 10 ++++++---- lib/rbot/ircsocket.rb | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index b2c7a88f..51457a56 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -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 diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb index 7b4175de..6ff93725 100644 --- a/lib/rbot/ircsocket.rb +++ b/lib/rbot/ircsocket.rb @@ -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) -- cgit v1.2.3