Class: CarbonMU::TelnetConnection

Inherits:
EdgeConnection show all
Extended by:
Forwardable
Defined in:
lib/carbonmu/edge_router/telnet_connection.rb

Instance Attribute Summary collapse

Attributes inherited from EdgeConnection

#id, #name

Instance Method Summary collapse

Methods inherited from EdgeConnection

#handle_input, #initialize, #shutdown

Constructor Details

This class inherits a constructor from CarbonMU::EdgeConnection

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket.



9
10
11
# File 'lib/carbonmu/edge_router/telnet_connection.rb', line 9

def socket
  @socket
end

Instance Method Details

#after_initialize(socket) ⇒ Object



11
12
13
14
# File 'lib/carbonmu/edge_router/telnet_connection.rb', line 11

def after_initialize(socket)
  @socket = socket
  async.run
end

#before_shutdownObject



28
29
30
# File 'lib/carbonmu/edge_router/telnet_connection.rb', line 28

def before_shutdown
  @socket.close unless @socket.closed?
end

#readObject



32
33
34
# File 'lib/carbonmu/edge_router/telnet_connection.rb', line 32

def read
  @socket.readpartial(4096)
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/carbonmu/edge_router/telnet_connection.rb', line 16

def run
  info "*** Received telnet connection #{id} from #{socket.addr[2]}"
  write "Connected. Your ID is #{id}\n"
  loop do
    async.handle_input(read)
  end
rescue EOFError, Errno::ECONNRESET
  info "*** Telnet connection #{id} disconnected"
  close
  terminate
end