Class: NNQ::REP0
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
Instance Method Summary collapse
-
#receive ⇒ Object
Cooked: returns the next request body.
-
#send(body, to:, header:) ⇒ Object
Raw: writes
bodywithheader(the opaque backtrace handed out by a prior #receive) back toto(the Connection from the same tuple). -
#send_reply(body) ⇒ Object
Cooked: routes
bodyback to the pipe the most recent #receive came from.
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
#receive ⇒ Object
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.
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.
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 |