lib/proxymachine/client_connection.rb in fizx-proxymachine-1.7.1 vs lib/proxymachine/client_connection.rb in fizx-proxymachine-1.8.0
- old
+ new
@@ -13,11 +13,11 @@
@remote = nil
@tries = 0
@connected = false
@connect_timeout = nil
@inactivity_timeout = nil
- ProxyMachine.incr
+ ProxyMachine.incr(self)
end
def peer
@peer ||=
begin
@@ -37,18 +37,18 @@
end
# Called when new data is available from the client but no remote
# server has been established. If a remote can be established, an
# attempt is made to connect and proxy to the remote server.
- def establish_remote_server
+ def establish_remote_server(routes = nil)
fail "establish_remote_server called with remote established" if @remote
- @routes = [ProxyMachine.router.call(@buffer.join)].flatten
+ @routes = [routes || ProxyMachine.router.call(@buffer.join, self) || {}].flatten
try_connect
end
-
+
attr_reader :inactivity_warning_timeout, :inactivity_warning_callback
-
+
def try_connect
@commands = @routes.shift
$logger.info "#{peer} #{@commands.inspect}"
close_connection unless @commands.instance_of?(Hash)
if remote = @commands[:remote]
@@ -102,11 +102,11 @@
@connected = true
@buffer.each { |data| @server_side.send_data(data) }
@buffer = []
proxy_incoming_to(@server_side, 10240)
end
-
+
def inactivity_warning_triggered
proc {
(@inactivity_warning_callback || ProxyMachine.inactivity_warning_callback).call(@remote.join(':'))
}
end
@@ -143,10 +143,10 @@
(@inactivity_error_callback || ProxyMachine.inactivity_error_callback).call(@remote.join(':'))
end
def unbind
@server_side.close_connection_after_writing if @server_side
- ProxyMachine.decr
+ ProxyMachine.decr(self)
end
# Proxy connection has been lost
def proxy_target_unbound
@server_side = nil