lib/envoy/client/trunk.rb in envoy-proxy-0.0.7 vs lib/envoy/client/trunk.rb in envoy-proxy-0.0.8
- old
+ new
@@ -7,10 +7,14 @@
module Trunk
include Protocol
attr_reader :options
+ def self.start options
+ EM.connect options[:server_host], options[:server_port].to_i, Envoy::Client::Trunk, options
+ end
+
def initialize options
@options = options
end
def channels
@@ -45,14 +49,29 @@
def receive_halt
EventMachine.stop_event_loop
end
def unbind
- EM.stop_event_loop
+ if @options[:reconnect]
+ STDERR.puts "No connection. Reconnecting in #{@options[:reconnect]}s."
+ EM.add_timer @options[:reconnect] do
+ @options[:reconnect] *= 2
+ Trunk.start @options
+ end
+ else
+ if options[:did_connect]
+ STDERR.puts "Connection lost. Not point reconnecting because the host is randomly generated."
+ else
+ STDERR.puts "Couldn't connect. Abandoning ship."
+ end
+ receive_halt
+ end
end
def ssl_handshake_completed
+ options[:did_connect] = true
+ options[:reconnect] = 1 if options[:hosts]
o = options.dup
o.delete(:local_host)
send_object :options, o
end
@@ -61,7 +80,6 @@
end
end
end
-end
-
+end
\ No newline at end of file