Class: CFTunnel
- Inherits:
-
Object
- Object
- CFTunnel
- Defined in:
- lib/tunnel-cf-plugin/tunnel.rb
Constant Summary collapse
- HELPER_NAME =
"caldecott"
- HELPER_APP =
File.("../../../helper-app", __FILE__)
- HELPER_VERSION =
bump this AND the version info reported by HELPER_APP/server.rb this is to keep the helper in sync with any updates here
"0.0.4"
- PORT_RANGE =
10
Instance Method Summary collapse
-
#initialize(client, service, port = 10000) ⇒ CFTunnel
constructor
A new instance of CFTunnel.
- #open! ⇒ Object
- #pick_port!(port = @port) ⇒ Object
- #wait_for_end ⇒ Object
- #wait_for_start ⇒ Object
Constructor Details
#initialize(client, service, port = 10000) ⇒ CFTunnel
Returns a new instance of CFTunnel.
16 17 18 19 20 |
# File 'lib/tunnel-cf-plugin/tunnel.rb', line 16 def initialize(client, service, port = 10000) @client = client @service = service @port = port end |
Instance Method Details
#open! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tunnel-cf-plugin/tunnel.rb', line 22 def open! if helper auth = helper_auth unless helper_healthy?(auth) delete_helper auth = create_helper end else auth = create_helper end bind_to_helper if @service && !helper_already_binds? info = get_connection_info(auth) start_tunnel(info, auth) info end |
#pick_port!(port = @port) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tunnel-cf-plugin/tunnel.rb', line 65 def pick_port!(port = @port) original = port PORT_RANGE.times do |n| begin TCPSocket.open("localhost", port) port += 1 rescue return @port = port end end @port = grab_ephemeral_port end |
#wait_for_end ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/tunnel-cf-plugin/tunnel.rb', line 56 def wait_for_end if @local_tunnel_thread @local_tunnel_thread.join else raise "Tunnel wasn't started!" end end |
#wait_for_start ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tunnel-cf-plugin/tunnel.rb', line 43 def wait_for_start 10.times do |n| begin TCPSocket.open("localhost", @port).close return true rescue => e sleep 1 end end raise "Could not connect to local tunnel." end |