lib/proxymachine/client_connection.rb in fizx-proxymachine-1.6.1 vs lib/proxymachine/client_connection.rb in fizx-proxymachine-1.7.0
- old
+ new
@@ -43,10 +43,12 @@
fail "establish_remote_server called with remote established" if @remote
@routes = [ProxyMachine.router.call(@buffer.join)].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]
@@ -58,12 +60,14 @@
if reply = @commands[:reply]
send_data(reply)
end
@connect_timeout = @commands[:connect_timeout]
@inactivity_timeout = @commands[:inactivity_timeout]
+ @inactivity_warning_timeout = @commands[:inactivity_warning_timeout]
@connect_error_callback = @commands[:connect_error_callback]
@inactivity_error_callback = @commands[:inactivity_error_callback]
+ @inactivity_warning_callback = @commands[:inactivity_warning_callback]
connect_to_server
elsif close = @commands[:close]
if close == true
close_connection
else
@@ -81,11 +85,11 @@
def connect_to_server
fail "connect_server called without remote established" if @remote.nil?
host, port = @remote
$logger.info "Establishing new connection with #{host}:#{port}"
cb = @commands[:callback]
- klass = cb ? CallbackServerConnection : ServerConnection
+ klass = cb ? CallbackServerConnection : WarningServerConnection
@server_side = klass.request(host, port, self)
@server_side.callback = cb if cb
@server_side.pending_connect_timeout = @connect_timeout
@server_side.comm_inactivity_timeout = @inactivity_timeout
end
@@ -97,9 +101,15 @@
$logger.info "Successful connection to #{@remote.join(':')}"
@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
# Called by the server side when a connection could not be established,
# either due to a hard connection failure or to a connection timeout.
# Leave the client connection open and retry the server connection up to