Class: NNQ::REP0

Inherits:
Socket show all
Defined in:
lib/nnq/req_rep.rb

Overview

REP (nng rep0): server side of request/reply. Cooked mode strictly alternates #receive / #send_reply and stashes the backtrace internally; raw mode exposes the backtrace as an opaque header and the originating pipe as a live Connection, so the app can drive the reply protocol itself (e.g. proxy/device use cases).

Instance Attribute Summary

Attributes inherited from Socket

#options

Instance Method Summary collapse

Methods inherited from Socket

#all_peers_gone, bind, #bind, #close, #close_read, connect, #connect, #connection_count, #frozen_binary, #initialize, #last_endpoint, #monitor, #peer_connected, #raw?, #reconnect_enabled, #reconnect_enabled=

Constructor Details

This class inherits a constructor from NNQ::Socket

Instance Method Details

#receiveObject

Cooked: returns the next request body. Raw: returns ‘[pipe, header, body]`.



68
69
70
# File 'lib/nnq/req_rep.rb', line 68

def receive
  Reactor.run { @engine.routing.receive }
end

#send(body, to:, header:) ⇒ Object

Raw: writes body with header (the opaque backtrace handed out by a prior #receive) back to to (the Connection from the same tuple). Silent drop if to is closed. Raises in cooked mode.

Raises:



85
86
87
88
89
# File 'lib/nnq/req_rep.rb', line 85

def send(body, to:, header:)
  raise Error, "REP#send not available in cooked mode" unless raw?
  body = frozen_binary(body)
  Reactor.run { @engine.routing.send(body, to: to, header: header) }
end

#send_reply(body) ⇒ Object

Cooked: routes body back to the pipe the most recent #receive came from. Raises in raw mode.

Raises:



75
76
77
78
79
# File 'lib/nnq/req_rep.rb', line 75

def send_reply(body)
  raise Error, "REP#send_reply not available in raw mode" if raw?
  body = frozen_binary(body)
  Reactor.run { @engine.routing.send_reply(body) }
end