Class: NNQ::Connection
- Inherits:
-
Object
- Object
- NNQ::Connection
- Defined in:
- lib/nnq/connection.rb
Overview
Per-pipe state: thin wrapper around Protocol::SP::Connection.
Owns no fibers itself — recv loop and send pump are spawned by the Engine and routing strategy respectively.
Instance Attribute Summary collapse
-
#endpoint ⇒ String?
readonly
Endpoint URI we connected to / accepted from.
- #sp ⇒ Protocol::SP::Connection readonly
Instance Method Summary collapse
-
#close ⇒ Object
Closes the underlying SP connection.
- #closed? ⇒ Boolean
-
#flush ⇒ void
Flushes the SP connection’s send buffer to the socket.
-
#initialize(sp, endpoint: nil) ⇒ Connection
constructor
A new instance of Connection.
-
#peer_protocol ⇒ Integer
Peer protocol id (e.g. Protocols::PULL_V0).
-
#receive_message ⇒ String
Reads one message body off the wire.
-
#send_message(body) ⇒ void
Writes one message AND flushes immediately.
-
#write_message(body) ⇒ void
Writes one message into the SP connection’s send buffer (no flush).
-
#write_messages(bodies) ⇒ void
Writes a batch of bodies under a single SP mutex acquisition.
Constructor Details
#initialize(sp, endpoint: nil) ⇒ Connection
Returns a new instance of Connection.
22 23 24 25 26 |
# File 'lib/nnq/connection.rb', line 22 def initialize(sp, endpoint: nil) @sp = sp @endpoint = endpoint @closed = false end |
Instance Attribute Details
#endpoint ⇒ String? (readonly)
Returns endpoint URI we connected to / accepted from.
17 18 19 |
# File 'lib/nnq/connection.rb', line 17 def endpoint @endpoint end |
#sp ⇒ Protocol::SP::Connection (readonly)
13 14 15 |
# File 'lib/nnq/connection.rb', line 13 def sp @sp end |
Instance Method Details
#close ⇒ Object
Closes the underlying SP connection. Safe to call twice.
90 91 92 93 94 |
# File 'lib/nnq/connection.rb', line 90 def close return if @closed @closed = true @sp.close end |
#closed? ⇒ Boolean
84 85 86 |
# File 'lib/nnq/connection.rb', line 84 def closed? @closed end |
#flush ⇒ void
This method returns an undefined value.
Flushes the SP connection’s send buffer to the socket.
70 71 72 |
# File 'lib/nnq/connection.rb', line 70 def flush @sp.flush end |
#peer_protocol ⇒ Integer
Returns peer protocol id (e.g. Protocols::PULL_V0).
30 31 32 |
# File 'lib/nnq/connection.rb', line 30 def peer_protocol @sp.peer_protocol end |
#receive_message ⇒ String
Reads one message body off the wire. Blocks the calling fiber.
78 79 80 |
# File 'lib/nnq/connection.rb', line 78 def @sp. end |
#send_message(body) ⇒ void
This method returns an undefined value.
Writes one message AND flushes immediately. Used by REQ/REP where each call is request-paced and there’s nothing to batch.
61 62 63 64 |
# File 'lib/nnq/connection.rb', line 61 def (body) raise ClosedError, "connection closed" if @closed @sp.(body) end |
#write_message(body) ⇒ void
This method returns an undefined value.
Writes one message into the SP connection’s send buffer (no flush).
39 40 41 42 |
# File 'lib/nnq/connection.rb', line 39 def (body) raise ClosedError, "connection closed" if @closed @sp.(body) end |
#write_messages(bodies) ⇒ void
This method returns an undefined value.
Writes a batch of bodies under a single SP mutex acquisition. Used by the work-stealing send pump hot path.
50 51 52 53 |
# File 'lib/nnq/connection.rb', line 50 def (bodies) raise ClosedError, "connection closed" if @closed @sp.(bodies) end |