Sha256: da11a289e6dad33aec63cd6858e52bdb28d7c52e47cb36b13032abefa15fb5bc

Contents?: true

Size: 894 Bytes

Versions: 5

Compression:

Stored size: 894 Bytes

Contents

module ZMQ
  
  # The context object encapsulates all the global state associated
  # with the library. 
  class Context
    
    # The FFI pointer to the context.
    attr_reader :pointer
    
    def initialize
      @pointer = LibZMQ.zmq_ctx_new
    end
    
    # Destroy the ØMQ context.
    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
    
    # Create a Socket within this context.
    def socket(type, opts={})
      opts[:context] = self
      ZMQ::Socket.new type, opts
    end
    
    # Returns the context's FFI pointer.
    def to_ptr
      @pointer
    end
    
  end
  
  # The default context to be used if another context is not provided.
  DefaultContext = Context.new
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
0mq-0.5.1 lib/0mq/context.rb
0mq-0.5.0 lib/0mq/context.rb
0mq-0.4.1 lib/0mq/context.rb
0mq-0.4.0 lib/0mq/context.rb
0mq-0.3.0 lib/0mq/context.rb