Permalink
Browse files

Merge pull request #5 from meh/deal-with-errors

Add catchable error handling
  • Loading branch information...
2 parents c2e3243 + dcb54d6 commit 806176d920c21eedf5b2aa5d8e5c96310c141fc3 @igrigorik committed Apr 16, 2012
Showing with 7 additions and 2 deletions.
  1. +2 −0 lib/em-socksify/socks5.rb
  2. +5 −2 lib/em-socksify/socksify.rb
@@ -100,6 +100,8 @@ def socks_parse_response
socks_unhook(ip)
end
+ rescue Exception => e
+ @socks_deferrable.fail(e)
end
def socks_methods
@@ -7,11 +7,14 @@ def socksify(host, port, username = nil, password = nil, version = 5, &blk)
@socks_username = username
@socks_password = password
@socks_version = version
- @socks_callback = blk
@socks_data = ''
socks_hook
socks_send_handshake
+
+ @socks_deferrable = DefaultDeferrable.new
+ @socks_deferrable.callback(&blk) if blk
+ @socks_deferrable
end
def socks_hook
@@ -31,7 +34,7 @@ class << self
remove_method :receive_data
end
- @socks_callback.call(ip)
+ @socks_deferrable.succeed(ip)
end
def socks_receive_data(data)

0 comments on commit 806176d

Please sign in to comment.