Class: Heroku::Client::Rendezvous

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/heroku/client/rendezvous.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Helpers

#app_urls, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, #display, #display_row, #display_table, #error, #fail, #format_bytes, #format_date, #get_terminal_environment, #git, #has_git?, #home_directory, #json_decode, #json_encode, #longest, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #time_ago, #truncate

Constructor Details

- (Rendezvous) initialize(input, output)

A new instance of Rendezvous



12
13
14
15
# File 'lib/heroku/client/rendezvous.rb', line 12

def initialize(input, output)
  @input = input
  @output = output
end

Instance Attribute Details

- (Object) input (readonly)

Returns the value of attribute input



10
11
12
# File 'lib/heroku/client/rendezvous.rb', line 10

def input
  @input
end

- (Object) output (readonly)

Returns the value of attribute output



10
11
12
# File 'lib/heroku/client/rendezvous.rb', line 10

def output
  @output
end

Instance Method Details

- (Object) connect(rendezvous_url)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/heroku/client/rendezvous.rb', line 22

def connect(rendezvous_url)
  uri = URI.parse(rendezvous_url)
  host, port, secret = uri.host, uri.port, uri.path[1..-1]

  socket = Timeout.timeout(30) do
    s = TCPSocket.open(host, port)
    s.puts(secret)
    s.readline; s.readline
    s
  end

  set_buffer(false)
  output.sync = true
  on_connect.call if on_connect

  loop do
    if o = IO.select([input, socket], nil, nil, nil)
      if o.first.first == input
        data = input.read_nonblock(1000)
        socket.write(data)
        socket.flush()
      elsif o.first.first == socket
        data = socket.read_nonblock(1000)
        output.write(data)
      end
    end
  end
rescue Timeout::Error
  error "\nTimeout awaiting process"
rescue Errno::ECONNREFUSED
  error "\nError connecting to process"
rescue Interrupt, EOFError, Errno::EIO
ensure
  set_buffer(true)
end

- (Object) on_connect(&blk)



17
18
19
20
# File 'lib/heroku/client/rendezvous.rb', line 17

def on_connect(&blk)
  @on_connect = blk if block_given?
  @on_connect
end