Class: ZMQ::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/0mq/context.rb

Overview

The context object encapsulates all the global state associated with the library.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



11
12
13
# File 'lib/0mq/context.rb', line 11

def initialize
  @pointer = LibZMQ.zmq_ctx_new
end

Instance Attribute Details

#pointerObject (readonly)

The FFI pointer to the context.



9
10
11
# File 'lib/0mq/context.rb', line 9

def pointer
  @pointer
end

Instance Method Details

#socket(type, opts = {}) ⇒ Object

Create a Socket within this context.



28
29
30
31
# File 'lib/0mq/context.rb', line 28

def socket(type, opts={})
  opts[:context] = self
  ZMQ::Socket.new type, opts
end

#terminateObject

Destroy the ØMQ context.



16
17
18
19
20
21
22
23
24
25
# File 'lib/0mq/context.rb', line 16

def terminate
  if @pointer
    rc = LibZMQ.version4?       ? 
      LibZMQ.zmq_ctx_term(@pointer) : 
      LibZMQ.zmq_term(@pointer)
    ZMQ.error_check true if rc == -1
    
    @pointer = nil
  end
end

#to_ptrObject

Returns the context’s FFI pointer.



34
35
36
# File 'lib/0mq/context.rb', line 34

def to_ptr
  @pointer
end