public
Description: Direct Connect bot written in Ruby
Clone URL: git://github.com/kballard/dcbot.git
Search Repo:
Add exception handling for connect_to_peer
kballard (author)
Wed Feb 27 19:39:12 -0800 2008
commit  2d19cf48643fd55d9573576e9ad8486894d7586f
tree    23933052f8337982488efdf25795912796a0a593
parent  55b49412f3ec09069481b650f750737546e3f71e
...
108
109
110
 
 
 
 
 
111
112
113
...
108
109
110
111
112
113
114
115
116
117
118
0
@@ -108,6 +108,11 @@ def setupConnection(host, port, nickname, sockopts, sleep)
0
     c.registerCallback :error do |socket, message|
0
       STDERR.puts "! #{message}"
0
     end
0
+ c.registerCallback :exception do |socket, message, exception|
0
+ STDERR.puts "! #{message}"
0
+ STDERR.puts exception.message
0
+ PP.pp(exception.backtrace, STDERR)
0
+ end
0
     c.registerCallback :peer_error do |socket, peer, message|
0
       STDERR.puts "! Peer #{peer.host}:#{peer.port}: #{message}"
0
     end
...
62
63
64
65
 
 
66
67
68
...
322
323
324
325
326
327
328
329
330
331
332
 
 
 
 
 
 
 
 
 
 
 
333
334
 
 
335
336
337
...
62
63
64
 
65
66
67
68
69
...
323
324
325
 
 
 
 
 
 
 
 
326
327
328
329
330
331
332
333
334
335
336
337
 
338
339
340
341
342
0
@@ -62,7 +62,8 @@ class DCProtocol < EventMachine::Connection
0
       begin
0
         proc.call(self, *args)
0
       rescue Exception => e
0
- STDERR.puts "Exception: #{e.message}\n#{e.backtrace}"
0
+ STDERR.puts "! Exception: #{e.message}"
0
+ STDERR.puts e.backtrace.join("\n")
0
       end
0
     end
0
   end
0
@@ -322,16 +323,20 @@ class DCClientProtocol < DCProtocol
0
   # utility methods
0
   
0
   def connect_to_peer(ip, port)
0
- @peers << EventMachine::connect(ip, port, DCPeerProtocol) do |c|
0
- parent = self
0
- debug = @debug || @config[:peer_debug]
0
- c.instance_eval do
0
- @parent = parent
0
- @host = ip
0
- @port = port
0
- @debug = debug
0
+ begin
0
+ @peers << EventMachine::connect(ip, port, DCPeerProtocol) do |c|
0
+ parent = self
0
+ debug = @debug || @config[:peer_debug]
0
+ c.instance_eval do
0
+ @parent = parent
0
+ @host = ip
0
+ @port = port
0
+ @debug = debug
0
+ end
0
+ c.call_callback :initialized
0
       end
0
- c.call_callback :initialized
0
+ rescue Exception => e
0
+ call_callback :exception, "Could not connect to peer #{ip}:#{port}", e
0
     end
0
   end
0
   

Comments

    No one has commented yet.