Module: EventMachine::Protocols::Zmq2::InProc

Defined in:
lib/em/protocols/zmq2/inproc.rb

Defined Under Namespace

Classes: AlreadyBinded, Connection, NotBinded

Constant Summary collapse

BindPoints =
{}

Class Method Summary collapse

Class Method Details

.bind(name, socket) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/em/protocols/zmq2/inproc.rb', line 9

def self.bind(name, socket)
  unless BindPoints[name].nil? || BindPoints[name] == socket
    raise AlreadyBinded, "ZMQ inproc://#{name} already binded"
  end
  BindPoints[name] = socket
  unless BindPoints[:shutdown_hook_set]
    BindPoints[:shutdown_hook_set] = true
    EM.add_shutdown_hook { BindPoints.clear }
  end
  name
end

.connect(name, socket) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/em/protocols/zmq2/inproc.rb', line 32

def self.connect(name, socket)
  connect = Connection.new(socket)
  EM.next_tick {
    if server = BindPoints[name]
      sconnect = Connection.new(server)
      sconnect.peer = connect
      connect.peer = sconnect
    else
      connect.unbind
    end
  }
  connect
end

.unbind(name, socket) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/em/protocols/zmq2/inproc.rb', line 21

def self.unbind(name, socket)
  unless BindPoints[name] == socket
    unless BindPoints[name]
      raise NotBinded, "ZMQ bind point inproc://#{name} binded to other socket"
    else
      raise NotBinded, "ZMQ bind point inproc://#{name} is not binded"
    end
  end
  BindPoints.delete name
end