Class: NNQ::REQ0

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

Overview

REQ (nng req0): client side of request/reply. Cooked mode keeps a single in-flight request and matches replies by id; raw mode bypasses the state machine entirely and delivers replies as ‘[pipe, header, body]` tuples so the app can correlate verbatim.

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

Raw: blocks until the next reply arrives, returns ‘[pipe, header, body]`. Raises in cooked mode.

Raises:



39
40
41
42
# File 'lib/nnq/req_rep.rb', line 39

def receive
  raise Error, "REQ#receive not available in cooked mode" unless raw?
  Reactor.run { @engine.routing.receive }
end

#send(body, header:) ⇒ Object

Raw: round-robins body to the next connected peer with header (typically ‘[id | 0x80000000].pack(“N”)`) written verbatim between the SP length prefix and the body. Raises in cooked mode.

Raises:



30
31
32
33
34
# File 'lib/nnq/req_rep.rb', line 30

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

#send_request(body) ⇒ Object

Cooked: sends body as a request, blocks until the matching reply arrives. Returns the reply body (without the id header). Raises in raw mode — use #send / #receive there.

Raises:



19
20
21
22
23
# File 'lib/nnq/req_rep.rb', line 19

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