nng/ctx
independent protocol state on one shared socket.
Since: Phase NG-C
NngCtx
(NngCtx)
a linear handle to one context on a socket.
Since: Phase NG-C
ctx-open
(ctx-open [^borrow s : Socket] :)
open a context on a socket.
| s | the socket (borrowed) |
(Result NngCtx int) -- err carries the nng error code: NNG_ENOTSUP on a protocol without contexts (PUB, PUSH, PULL, PAIR, BUS).
(let [c (ok-val (ctx-open rep))]
(serve c)
(ctx-close c))
Since: Phase NG-C
ctx-close
(ctx-close [c : NngCtx] :)
close a context. The single linear consumer.
| c | the context, consumed |
(ctx-close c)
Since: Phase NG-C
ctx-send-payload
(ctx-send-payload [^borrow c : NngCtx b : Payload])
send a byte buffer on the context; blocks.
| c | the context (borrowed) | |
| b | the payload (borrowed) |
(Result nil int) -- err carries the nng error code.
(ctx-send-payload c reply)
Since: Phase NG-C
ctx-recv-payload
(ctx-recv-payload [^borrow c : NngCtx])
receive one message on the context; blocks.
| c | the context (borrowed) |
(Result Payload int) -- ok carries a fresh Payload the caller frees with payload-free; err carries the nng error code (NNG_ETIMEDOUT after the context's receive timeout).
(let [r (ctx-recv-payload c)]
(when (ok? r) (payload-free (ok-val r))))
Since: Phase NG-C
ctx-send-str
(ctx-send-str [^borrow c : NngCtx msg : cstr])
send a NUL-terminated string on the context; blocks.
| c | the context (borrowed) | |
| msg | the payload (borrowed) |
(Result nil int) -- err carries the nng error code.
(ctx-send-str c "pong")
Since: Phase NG-C
ctx-recv-str
(ctx-recv-str [^borrow c : NngCtx])
receive one message on the context as a malloc'd cstr.
| c | the context (borrowed) |
(Result cstr int) -- err carries the nng error code.
(let [r (ctx-recv-str c)]
(when (ok? r) (println (ok-val r))))
Since: Phase NG-C
ctx-send-payload-aio
(ctx-send-payload-aio [^borrow c : NngCtx ^borrow a : Aio b : Payload])
submit a send of a byte buffer on the context.
| c | the context (borrowed) | |
| a | the slot (borrowed) | |
| b | the payload (borrowed) |
(Result nil int) -- ok: submitted; err: nothing submitted (NNG_EBUSY while the slot has an operation in flight).
(ctx-send-payload-aio c a b)
Since: Phase NG-C
ctx-send-str-aio
(ctx-send-str-aio [^borrow c : NngCtx ^borrow a : Aio msg : cstr])
submit a send of a NUL-terminated string on the context.
| c | the context (borrowed) | |
| a | the slot (borrowed) | |
| msg | the payload (borrowed) |
(Result nil int) -- ok: submitted; err: nothing submitted.
(ctx-send-str-aio c a "q1")
Since: Phase NG-C
ctx-recv-aio
(ctx-recv-aio [^borrow c : NngCtx ^borrow a : Aio])
submit a receive on the context.
| c | the context (borrowed) | |
| a | the slot (borrowed) |
(Result nil int) -- ok: submitted; err: nothing submitted.
(ctx-recv-aio c a)
Since: Phase NG-C
ctx-set-recv-timeout-ms
(ctx-set-recv-timeout-ms [^borrow c : NngCtx ms : int] :)
this context's receive timeout.
| c | the context (borrowed) | |
| ms | milliseconds; -1 waits forever |
(Result nil int) -- err carries the nng error code.
(ctx-set-recv-timeout-ms c 2000)
Since: Phase NG-C
ctx-set-send-timeout-ms
(ctx-set-send-timeout-ms [^borrow c : NngCtx ms : int] :)
this context's send timeout.
| c | the context (borrowed) | |
| ms | milliseconds; -1 waits forever |
(Result nil int) -- err carries the nng error code.
(ctx-set-send-timeout-ms c 2000)
Since: Phase NG-C
ctx-subscribe
(ctx-subscribe [^borrow c : NngCtx topic : cstr] :)
add a topic prefix filter to a SUB context.
| c | the context (borrowed); on anything but SUB, err NNG_ENOTSUP | |
| topic | the byte prefix to accept; "" accepts every message |
(Result nil int) -- err carries the nng error code.
(ctx-subscribe c "temp:")
Since: Phase NG-C
ctx-unsubscribe
(ctx-unsubscribe [^borrow c : NngCtx topic : cstr] :)
drop a topic prefix filter from a SUB context.
| c | the context (borrowed) | |
| topic | the exact prefix passed to ctx-subscribe; anything else is | |
| err NNG_ENOENT |
(Result nil int) -- err carries the nng error code.
(ctx-unsubscribe c "temp:")
Since: Phase NG-C