Class: Erlang::EpmdConnection

Inherits:
EM::Connection
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/rinterface/epmd.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nodenameObject

Returns the value of attribute nodename.



8
9
10
# File 'lib/rinterface/epmd.rb', line 8

def nodename
  @nodename
end

Class Method Details

.lookup_node(nodename) ⇒ Object



10
11
12
13
14
# File 'lib/rinterface/epmd.rb', line 10

def self.lookup_node(nodename)
  EM.connect("127.0.0.1",4369,self) do |conn|
    conn.nodename = nodename
  end
end

Instance Method Details

#connection_completedObject



16
17
18
# File 'lib/rinterface/epmd.rb', line 16

def connection_completed
  send_data lookup_port
end

#lookup_portObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rinterface/epmd.rb', line 27

def lookup_port
  out = StringIO.new('', 'w')

  # Create the header with length: 2
  out.write([@nodename.size + 1].pack('n'))

  # Next the request
  # tag. Length: 1
  out.write([122].pack("C"))
  # nodename
  out.write(nodename)
  out.string
end

#parse_response(input) ⇒ Object

If we get a good result we only return the port (not reading all the information



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rinterface/epmd.rb', line 43

def parse_response(input)
  i = StringIO.new(input)
  code = i.read(1).unpack('C').first
  result = i.read(1).unpack('C').first
  if result == 0
    # good response read the port
    port = i.read(2).unpack('n').first
    set_deferred_success port
  else
    set_deferred_failure 0
  end
end

#receive_data(data) ⇒ Object



20
21
22
# File 'lib/rinterface/epmd.rb', line 20

def receive_data(data)
  parse_response(data)
end

#unbindObject



24
25
# File 'lib/rinterface/epmd.rb', line 24

def unbind
end