diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-07-22 15:50:30 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-07-22 15:50:30 +0000 |
commit | a2c9a18474c4cb50d45aebb58c2d47bd98a886e7 (patch) | |
tree | b35a422eac4fac2bf58d852730ee03fd48d0ccb7 /lib | |
parent | b482ed5c732e5148af342ef12ee8bf1c7acd971c (diff) |
Better interruption handling, saner generic exception handling
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rbot/ircbot.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index ea9b46ad..f1aa7e50 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -423,7 +423,8 @@ class IrcBot debug "failed to trap signals: #{e.inspect}" end begin - @socket.connect unless $interrupted > 0 + quit if $interrupted > 0 + @socket.connect rescue => e raise e.class, "failed to connect to IRC server at #{@config['server.name']} #{@config['server.port']}: " + e end @@ -436,6 +437,7 @@ class IrcBot def mainloop while true begin + quit if $interrupted > 0 connect @timer.start @@ -444,7 +446,7 @@ class IrcBot break unless reply = @socket.gets @client.process reply end - quit if $interrupted > 0 + quit if $interrupted > 0 end # I despair of this. Some of my users get "connection reset by peer" @@ -453,23 +455,19 @@ class IrcBot rescue SystemExit log_session_end exit 0 - rescue TimeoutError, SocketError => e + rescue Errno::ETIMEDOUT, TimeoutError, SocketError => e error "network exception: #{e.class}: #{e}" - debug e.inspect debug e.backtrace.join("\n") rescue BDB::Fatal => e error "fatal bdb error: #{e.class}: #{e}" - error e.inspect error e.backtrace.join("\n") DBTree.stats restart("Oops, we seem to have registry problems ...") rescue Exception => e error "non-net exception: #{e.class}: #{e}" - error e.inspect error e.backtrace.join("\n") rescue => e error "unexpected exception: #{e.class}: #{e}" - error e.inspect error e.backtrace.join("\n") log_session_end exit 2 @@ -484,6 +482,8 @@ class IrcBot log "disconnected" + quit if $interrupted > 0 + log "waiting to reconnect" sleep @config['server.reconnect_wait'] end |