Module: EMRPC::RemoteConnection

Includes:
ConnectionMixin
Defined in:
lib/emrpc/evented_api/remote_connection.rb

Instance Attribute Summary collapse

Attributes included from ConnectionMixin

#connected_callback, #disconnected_callback, #local_pid, #remote_pid

Instance Method Summary collapse

Instance Attribute Details

#addressObject

Returns the value of attribute address.



4
5
6
# File 'lib/emrpc/evented_api/remote_connection.rb', line 4

def address
  @address
end

Instance Method Details

#connection_completedObject

Handshake protocol



19
20
21
# File 'lib/emrpc/evented_api/remote_connection.rb', line 19

def connection_completed
  send_handshake_message(@local_pid.options)
end

#post_initObject

IMPORTANT: server doesn’t trigger #connection_completed callback.



9
10
11
12
13
14
# File 'lib/emrpc/evented_api/remote_connection.rb', line 9

def post_init
  # setup single-shot version of receive_marshalled_message
  class <<self
    alias_method :receive_marshalled_message, :receive_handshake_message
  end
end

#receive_handshake_message(msg) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/emrpc/evented_api/remote_connection.rb', line 28

def receive_handshake_message(msg)
  prefix, options = msg
  lpid = @local_pid
  prefix == :handshake or return lpid.handshake_failed(self, msg)
  rpid = RemotePid.new(self, options)
  # restore receive_marshalled_message
  class <<self
    alias_method :receive_marshalled_message, :receive_regular_message
  end
  unless @__sent_handshake # server-side
    send_handshake_message(@local_pid.options)
  end
  @remote_pid = lpid.connection_established(rpid, self)
end

#receive_regular_message(msg) ⇒ Object



50
51
52
53
# File 'lib/emrpc/evented_api/remote_connection.rb', line 50

def receive_regular_message(msg)
  lpid = @local_pid
  lpid.__send__(*(msg.decode_b381b571_1ab2_5889_8221_855dbbc76242(lpid)))
end

#rescue_marshal_error(e) ⇒ Object



55
56
57
# File 'lib/emrpc/evented_api/remote_connection.rb', line 55

def rescue_marshal_error(e)
  raise e
end

#send_handshake_message(arg) ⇒ Object



23
24
25
26
# File 'lib/emrpc/evented_api/remote_connection.rb', line 23

def send_handshake_message(arg)
  @__sent_handshake = true
  send_marshalled_message([:handshake, arg])
end

#send_raw_message(args) ⇒ Object

Regular protocol



46
47
48
# File 'lib/emrpc/evented_api/remote_connection.rb', line 46

def send_raw_message(args)
  send_marshalled_message(args.encode_b381b571_1ab2_5889_8221_855dbbc76242(@local_pid))
end

#unbindObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/emrpc/evented_api/remote_connection.rb', line 59

def unbind
  if @remote_pid
    # pid has been succesfully connected one day, but connection was lost.
    # we don't put +_unregister_pid+ into +connection_lost+ callback to avoid unneccessary +super+ calls in callbacks.
    rpid = @remote_pid
    @remote_pid = nil
    @local_pid.connection_unbind(rpid, self)
  else
    # there were no connection, connecting failed. 
    @local_pid.connection_failed(self)
  end
end