Class: EventMachine::ZeroMQ::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/em-zeromq/context.rb

Instance Method Summary collapse

Constructor Details

#initialize(threads_or_context) ⇒ Context

Returns a new instance of Context.



12
13
14
15
16
17
18
# File 'lib/em-zeromq/context.rb', line 12

def initialize(threads_or_context)
  if threads_or_context.is_a?(ZMQ::Context)
    @context = threads_or_context
  else
    @context = ZMQ::Context.new(threads_or_context)
  end
end

Instance Method Details

#socket(socket_type) ⇒ Object

Create a socket in this context.

Parameters:

  • socket_type (Integer)

    One of ZMQ::REQ, ZMQ::REP, ZMQ::PULL, ZMQ::PUSH, ZMQ::ROUTER, ZMQ::DEALER



27
28
29
30
31
32
33
34
35
36
# File 'lib/em-zeromq/context.rb', line 27

def socket(socket_type)
  zmq_socket = @context.socket(socket_type)
  
  fd = []
  if zmq_socket.getsockopt(ZMQ::FD, fd) < 0
    raise "Unable to get socket FD: #{ZMQ::Util.error_string}"
  end
  
  EM.watch(fd[0], EventMachine::ZeroMQ::Socket, zmq_socket, socket_type)
end