Add catchable error handling #5

Merged
merged 2 commits into from Apr 16, 2012
View
2 lib/em-socksify/socks5.rb
@@ -100,6 +100,8 @@ def socks_parse_response
socks_unhook(ip)
end
+ rescue Exception => e
+ @socks_deferrable.fail(e)
end
def socks_methods
View
7 lib/em-socksify/socksify.rb
@@ -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)