Class: CZTop::Socket::ROUTER

Inherits:
CZTop::Socket show all
Defined in:
lib/cztop/socket/types.rb

Overview

Router socket for the ZeroMQ Request-Reply Pattern.

Constant Summary

Constants inherited from CZTop::Socket

TypeNames

Constants included from CZTop::SendReceiveMethods

CZTop::SendReceiveMethods::JIFFY

Instance Attribute Summary

Attributes inherited from CZTop::Socket

#last_tcp_port

Attributes included from HasFFIDelegate

#ffi_delegate

Instance Method Summary collapse

Methods inherited from CZTop::Socket

#CURVE_client!, #CURVE_server!, #bind, #close, #connect, #disconnect, #inspect, #last_endpoint, new_by_type, #unbind

Methods included from HasFFIDelegate::ClassMethods

#ffi_delegate, #from_ffi_delegate

Methods included from PolymorphicZsockMethods

#set_unbounded, #signal, #wait

Methods included from CZTop::SendReceiveMethods

#<<, #read_timeout, #receive, #wait_readable, #write_timeout

Methods included from ZsockOptions

#fd, #options, #readable?, #to_io, #writable?

Methods included from HasFFIDelegate

#attach_ffi_delegate, #from_ffi_delegate, raise_zmq_err, #to_ptr

Constructor Details

#initialize(endpoints = nil) ⇒ ROUTER

Returns a new instance of ROUTER.

Parameters:

  • endpoints (String) (defaults to: nil)

    endpoints to bind to



152
153
154
155
156
# File 'lib/cztop/socket/types.rb', line 152

def initialize(endpoints = nil)
  super

  attach_ffi_delegate(Zsock.new_router(endpoints))
end

Instance Method Details

#send_to(receiver, message) ⇒ Object

Note:

Do NOT use the message afterwards. It’ll have been modified and destroyed.

Send a message to a specific receiver. This is a shorthand for when you send a message to a specific receiver with no hops in between.

Parameters:

  • receiver (String)

    receiving peer’s socket identity

  • message (Message)

    the message to send



165
166
167
168
169
170
# File 'lib/cztop/socket/types.rb', line 165

def send_to(receiver, message)
  message = Message.coerce(message)
  message.prepend ''       # separator frame
  message.prepend receiver # receiver envelope
  self << message
end

#wait_writableObject

Raises:

  • (SocketError)

    if ZMQ_ROUTER_MANDATORY option and message is currently not routable



174
175
176
177
178
179
180
# File 'lib/cztop/socket/types.rb', line 174

def wait_writable(...)
  if options.router_mandatory? && !writable?
    fail SocketError, "no peer connected"
  end

  super
end