lib/proxymachine/client_connection.rb in fizx-proxymachine-1.4.0 vs lib/proxymachine/client_connection.rb in fizx-proxymachine-1.5.0
- old
+ new
@@ -53,10 +53,12 @@
if reply = @commands[:reply]
send_data(reply)
end
@connect_timeout = @commands[:connect_timeout]
@inactivity_timeout = @commands[:inactivity_timeout]
+ @connect_error_callback = @commands[:connect_error_callback]
+ @inactivity_error_callback = @commands[:inactivity_error_callback]
connect_to_server
elsif close = @commands[:close]
if close == true
close_connection
else
@@ -101,19 +103,19 @@
def server_connection_failed
@server_side = nil
if @connected
$logger.error "Connection with #{@remote.join(':')} was terminated prematurely."
close_connection
- ProxyMachine.connect_error_callback.call(@remote.join(':'))
+ (@connect_error_callback || ProxyMachine.connect_error_callback).call(@remote.join(':'))
elsif @tries < 10
@tries += 1
$logger.warn "Retrying connection with #{@remote.join(':')} (##{@tries})"
EM.add_timer(0.1) { connect_to_server }
else
$logger.error "Connect #{@remote.join(':')} failed after ten attempts."
close_connection
- ProxyMachine.connect_error_callback.call(@remote.join(':'))
+ (@connect_error_callback || ProxyMachine.connect_error_callback).call(@remote.join(':'))
end
end
# Called by the server when an inactivity timeout is detected. The timeout
# argument is the configured inactivity timeout in seconds as a float; the
@@ -121,10 +123,10 @@
# connecting but not receiving any data.
def server_inactivity_timeout(timeout, elapsed)
$logger.error "Disconnecting #{@remote.join(':')} after #{elapsed}s of inactivity (> #{timeout.inspect})"
@server_side = nil
close_connection
- ProxyMachine.inactivity_error_callback.call(@remote.join(':'))
+ (@inactivity_error_callback || ProxyMachine.inactivity_error_callback).call(@remote.join(':'))
end
def unbind
@server_side.close_connection_after_writing if @server_side
ProxyMachine.decr