summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-06-28 16:02:24 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-06-28 16:02:24 +0000
commitd764894efae89970e22bad48db4c76d878b35630 (patch)
tree8ad362f53df602b856d2d4132b56e05dc0afdade /lib/rbot
parent1676abaf61c9b6c40714e00d6637e3a73d8b527b (diff)
Fix issue #101
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/ircbot.rb10
-rw-r--r--lib/rbot/ircsocket.rb8
2 files changed, 13 insertions, 5 deletions
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)