Sha256: 565d0a54384b4b30c8675ea045863d6c3e68f572f82ec75a30ec4e5f12b484a2

Contents?: true

Size: 1.47 KB

Versions: 28

Compression:

Stored size: 1.47 KB

Contents

# encoding: utf-8

class ZMQ::Context

  # Overload the libczmq handler installed for SIGINT and SIGTERM on context init. This ensures we fallback to the default
  # Ruby signal handlers which is least likely to violate the principle of least surprise. As an alternative fallback, we
  # expose ZMQ.interrupted! which reverts back to the libczmq default actions when called from a Ruby signal handler. The
  # following restores the default libczmq behavior :
  #
  # def initialize(*args)
  #   super
  #   trap(:INT){ ZMQ.interrupted! }
  #   trap(:TERM){ ZMQ.interrupted! }
  # end
  #

  def initialize(*args)
    super
    trap(:INT, "DEFAULT")
    trap(:TERM, "DEFAULT")
  end

  # Before using any ØMQ library functions the caller must initialise a ØMQ context.
  #
  # The context manages open sockets and automatically closes these before termination. Other responsibilities include :
  #
  # * A simple way to set the linger timeout on sockets
  # * C onfigure contexts for a number of I/O threads
  # * Sets-up signal (interrrupt) handling for the process.

  # Sugaring for spawning a new socket and bind to a given endpoint
  #
  # ctx.bind(:PUB, "tcp://127.0.0.1:5000")
  #
  def bind(sock_type, endpoint)
    s = socket(sock_type)
    s.bind(endpoint)
    s
  end

  # Sugaring for spawning a new socket and connect to a given endpoint
  #
  # ctx.connect(:SUB, "tcp://127.0.0.1:5000")
  #
  def connect(sock_type, endpoint)
    s = socket(sock_type)
    s.connect(endpoint)
    s
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
rbczmq-1.7.9 lib/zmq/context.rb
rbczmq-1.7.8 lib/zmq/context.rb
rbczmq-1.7.7 lib/zmq/context.rb
rbczmq-1.7.6 lib/zmq/context.rb
rbczmq-1.7.5 lib/zmq/context.rb
rbczmq-1.7.4 lib/zmq/context.rb
rbczmq-1.7.3 lib/zmq/context.rb
rbczmq-1.7.2 lib/zmq/context.rb
rbczmq-1.7.1 lib/zmq/context.rb
rbczmq-1.7.0 lib/zmq/context.rb
rbczmq-1.6.4 lib/zmq/context.rb
rbczmq-1.6.2 lib/zmq/context.rb
rbczmq-1.6 lib/zmq/context.rb
rbczmq-1.5 lib/zmq/context.rb
rbczmq-1.4 lib/zmq/context.rb
rbczmq-1.3 lib/zmq/context.rb
rbczmq-1.2 lib/zmq/context.rb
rbczmq-1.1 lib/zmq/context.rb
rbczmq-1.0 lib/zmq/context.rb
rbczmq-0.9 lib/zmq/context.rb