diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-09-07 19:16:34 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-09-07 19:16:34 +0000 |
commit | 42fd60e6a81e592553cdc6bb3b6011386692dde2 (patch) | |
tree | f09c025d4bed903701f624e17821bfdac38e106a | |
parent | 6dad1b9c510db00be89196ee3cf514046c1e35a8 (diff) |
win32 thing for signal handling
fix quit! :p
-rw-r--r-- | lib/rbot/ircbot.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 2443ec95..91afd94e 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -316,7 +316,7 @@ class IrcBot end begin @socket.connect - rescue => e + rescue => e raise "failed to connect to IRC server at #{@config['server.name']} #{@config['server.port']}: " + e end @socket.puts "PASS " + @config['server.password'] if @config['server.password'] @@ -341,8 +341,10 @@ class IrcBot # exceptions that ARENT SocketError's. How am I supposed to handle # that? #rescue TimeoutError, SocketError => e + rescue SystemExit + exit 0 rescue Exception => e - puts "network exception: connection closed: #{e}" + puts "network exception: connection closed: #{e.inspect}" puts e.backtrace.join("\n") @socket.shutdown # now we reconnect rescue => e @@ -451,9 +453,13 @@ class IrcBot # disconnect from the server and cleanup all plugins and modules def shutdown(message = nil) - trap("SIGTERM", "DEFAULT") - trap("SIGHUP", "DEFAULT") - trap("SIGINT", "DEFAULT") + begin + trap("SIGTERM", "DEFAULT") + trap("SIGHUP", "DEFAULT") + trap("SIGINT", "DEFAULT") + rescue + debug "failed to trap signals, probably running on windows?" + end message = @lang.get("quit") if (message.nil? || message.empty?) @socket.clearq save @@ -461,18 +467,21 @@ class IrcBot @channels.each_value {|v| log "@ quit (#{message})", v.name } + @registry.close @socket.puts "QUIT :#{message}" @socket.flush @socket.shutdown - @registry.close puts "rbot quit (#{message})" end # message:: optional IRC quit message # quit IRC, shutdown the bot def quit(message=nil) - shutdown(message) - exit 0 + begin + shutdown(message) + ensure + exit 0 + end end # totally shutdown and respawn the bot |