Class: Pgai::Port::Forwarder

Inherits:
Object
  • Object
show all
Defined in:
lib/pgai/port/forwarder.rb

Constant Summary collapse

LOCALHOST =
"127.0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_port, remote_host, remote_port, logger: Pgai::Commander.instance.logger) ⇒ Forwarder

Returns a new instance of Forwarder.



13
14
15
16
17
18
19
# File 'lib/pgai/port/forwarder.rb', line 13

def initialize(local_port, remote_host, remote_port, logger: Pgai::Commander.instance.logger)
  @local_port = local_port
  @remote_host = remote_host
  @remote_port = remote_port
  @logger = logger
  @child, @parent = Socket.pair(:UNIX, :DGRAM)
end

Instance Attribute Details

#local_portObject (readonly)

Returns the value of attribute local_port.



11
12
13
# File 'lib/pgai/port/forwarder.rb', line 11

def local_port
  @local_port
end

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'lib/pgai/port/forwarder.rb', line 11

def logger
  @logger
end

#remote_hostObject (readonly)

Returns the value of attribute remote_host.



11
12
13
# File 'lib/pgai/port/forwarder.rb', line 11

def remote_host
  @remote_host
end

#remote_portObject (readonly)

Returns the value of attribute remote_port.



11
12
13
# File 'lib/pgai/port/forwarder.rb', line 11

def remote_port
  @remote_port
end

Instance Method Details

#startObject



21
22
23
24
25
26
27
28
# File 'lib/pgai/port/forwarder.rb', line 21

def start
  return if ready?

  debug "starting"
  start_ssh_connection
  wait_until_ready
  debug "ready to accept connections"
end

#stopObject



30
31
32
33
34
35
36
37
38
# File 'lib/pgai/port/forwarder.rb', line 30

def stop
  return unless @pid

  @parent.write("exit")
  debug "shutting down"
  Process.wait(@pid)
  debug "exit"
  @pid = nil
end