No matching definitions.

nng/msg

src/nng/msg.tur

blocking send and receive over an nng socket.

Since: Phase NG2

defn

send-str

(send-str [^borrow s : Socket msg : cstr])

send a NUL-terminated string as one message.

sthe socket (borrowed)
msgthe payload (borrowed; the caller keeps ownership)

(Result nil int) -- err carries the nng error code.

(send-str s "job:42")

Since: Phase NG2

defn

recv-str

(recv-str [^borrow s : Socket])

receive one message as a malloc'd cstr; the caller frees it.

sthe socket (borrowed)

(Result cstr int) -- ok carries a fresh malloc'd string; err carries the nng error code.

(let [r (recv-str s)]
    (if (ok? r) (println (ok-val r)) (println (err-str (err-val r)))))

Since: Phase NG2

defn

send-payload

(send-payload [^borrow s : Socket b : Payload])

send a byte buffer as one message.

sthe socket (borrowed)
bthe payload (borrowed)

(Result nil int) -- err carries the nng error code.

(let [b (payload-of-cstr "job:42")]
    (send-payload s b)
    (payload-free b))

Since: Phase NG2

defn

recv-payload

(recv-payload [^borrow s : Socket])

receive one message as an owned Payload; the caller frees it.

sthe socket (borrowed)

(Result Payload int) -- ok carries a fresh owned Payload; release it with `payload-free`. err carries the nng error code.

(let [r (recv-payload s)]
    (when (ok? r)
      (let [b (ok-val r)]
        (println (payload->hex b))
        (payload-free b))))

Since: Phase NG2

defn

try-recv-str

(try-recv-str [^borrow s : Socket])

receive one message if one is waiting; never blocks.

sthe socket (borrowed)

(Result (Option cstr) int) -- (ok (some m)) a fresh malloc'd string the caller frees; (ok (none)) nothing is waiting; (err code) any other failure, e.g. NNG_ENOTSUP on a socket that cannot receive.

(match (ok-val (try-recv-str s))
    (Some m) (handle m)
    (None)   (println "nothing yet"))

Since: Phase NG-A

defn

try-recv-payload

(try-recv-payload [^borrow s : Socket])

receive one binary message if one is waiting.

sthe socket (borrowed)

(Result (Option Payload) int) -- (ok (some b)) a fresh owned Payload the caller releases with payload-free; (ok (none)) nothing is waiting; (err code) any other failure.

(match (ok-val (try-recv-payload s))
    (Some b) (do (handle b) (payload-free b))
    (None)   nil)

Since: Phase NG-A

defn

try-send-str

(try-send-str [^borrow s : Socket msg : cstr])

send a string if the socket can take it now; never blocks.

sthe socket (borrowed)
msgthe payload (borrowed)

(Result bool int) -- (ok true) sent; (ok false) the send would block (no peer ready, or its queue is full) and nothing was sent; (err code) any other failure, e.g. NNG_ENOTSUP on a socket that cannot send.

(when (not (ok-val (try-send-str s "job:42")))
    (retry-later))

Since: Phase NG-A

defn

try-send-payload

(try-send-payload [^borrow s : Socket b : Payload])

send a byte buffer if the socket can take it now.

sthe socket (borrowed)
bthe payload (borrowed)

(Result bool int) -- (ok true) sent; (ok false) the send would block and nothing was sent; (err code) any other failure.

(let [b (payload-of-cstr "job:42")]
    (try-send-payload s b)
    (payload-free b))

Since: Phase NG-A

defn

sub-subscribe

(sub-subscribe [^borrow s : Socket topic : cstr] :)

add a topic prefix filter to a SUB socket.

sthe socket (borrowed); must be a SUB socket, or the result is
`err` carrying NNG_ENOTSUP. v0 ships one `Socket` type, so that
is a runtime error rather than a compile-time one.
topicthe byte prefix to accept; "" accepts every message

(Result nil int) -- err carries the nng error code.

(sub-subscribe s "temp:")

Since: Phase NG3

defn

sub-unsubscribe

(sub-unsubscribe [^borrow s : Socket topic : cstr] :)

drop a topic prefix filter from a SUB socket.

sthe socket (borrowed); must be a SUB socket
topicthe exact prefix passed to `sub-subscribe`

(Result nil int) -- err carries the nng error code.

(sub-unsubscribe s "temp:")

Since: Phase NG3