Module: ZMQMachine::Socket::EnvelopeHelp

Included in:
XRep, XReq
Defined in:
lib/zm/sockets/envelope_help.rb

Overview

Two socket types (XREQ/XREP also called DEALER/ROUTER) have message parts for routing the message to the appropriate destination. This extra routing data is commonly called the routing envelope.

The module provides logic for separating the routing envelope from the message body. The envelope is passed separately to the user’s #on_readable method.

Instance Method Summary collapse

Instance Method Details

#resume_readObject

Used by the reactor. Never called by user code.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/zm/sockets/envelope_help.rb', line 25

def resume_read
  rc = 0
  more = true

  while ZMQ::Util.resultcode_ok?(rc) && more
    parts, envelope = [], []
    rc = @raw_socket.recv_multipart parts, envelope, ZMQ::Util.nonblocking_flag

    if ZMQ::Util.resultcode_ok?(rc)
      @handler.on_readable self, parts, envelope
    else
      # verify errno corresponds to EAGAIN
      if eagain?
        more = false
      elsif valid_socket_error?
        @handler.on_readable_error self, rc
      end
    end
  end
end

#send_messages(messages, envelope = nil) ⇒ Object

Convenience method for sending a multi-part message. The messages and envelope arguments must implement Enumerable.



19
20
21
# File 'lib/zm/sockets/envelope_help.rb', line 19

def send_messages messages, envelope = nil
  envelope ? @raw_socket.sendmsgs(envelope + messages) : @raw_socket.sendmsgs(messages)
end