No matching definitions.

nng/ctx

src/nng/ctx.tur

independent protocol state on one shared socket.

Since: Phase NG-C

defopaque

NngCtx

(NngCtx)

a linear handle to one context on a socket.

Since: Phase NG-C

defn

ctx-open

(ctx-open [^borrow s : Socket] :)

open a context on a socket.

sthe 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

defn

ctx-close

(ctx-close [c : NngCtx] :)

close a context. The single linear consumer.

cthe context, consumed
(ctx-close c)

Since: Phase NG-C

defn

ctx-send-payload

(ctx-send-payload [^borrow c : NngCtx b : Payload])

send a byte buffer on the context; blocks.

cthe context (borrowed)
bthe payload (borrowed)

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

(ctx-send-payload c reply)

Since: Phase NG-C

defn

ctx-recv-payload

(ctx-recv-payload [^borrow c : NngCtx])

receive one message on the context; blocks.

cthe 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

defn

ctx-send-str

(ctx-send-str [^borrow c : NngCtx msg : cstr])

send a NUL-terminated string on the context; blocks.

cthe context (borrowed)
msgthe payload (borrowed)

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

(ctx-send-str c "pong")

Since: Phase NG-C

defn

ctx-recv-str

(ctx-recv-str [^borrow c : NngCtx])

receive one message on the context as a malloc'd cstr.

cthe 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

defn

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.

cthe context (borrowed)
athe slot (borrowed)
bthe 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

defn

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.

cthe context (borrowed)
athe slot (borrowed)
msgthe payload (borrowed)

(Result nil int) -- ok: submitted; err: nothing submitted.

(ctx-send-str-aio c a "q1")

Since: Phase NG-C

defn

ctx-recv-aio

(ctx-recv-aio [^borrow c : NngCtx ^borrow a : Aio])

submit a receive on the context.

cthe context (borrowed)
athe slot (borrowed)

(Result nil int) -- ok: submitted; err: nothing submitted.

(ctx-recv-aio c a)

Since: Phase NG-C

defn

ctx-set-recv-timeout-ms

(ctx-set-recv-timeout-ms [^borrow c : NngCtx ms : int] :)

this context's receive timeout.

cthe context (borrowed)
msmilliseconds; -1 waits forever

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

(ctx-set-recv-timeout-ms c 2000)

Since: Phase NG-C

defn

ctx-set-send-timeout-ms

(ctx-set-send-timeout-ms [^borrow c : NngCtx ms : int] :)

this context's send timeout.

cthe context (borrowed)
msmilliseconds; -1 waits forever

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

(ctx-set-send-timeout-ms c 2000)

Since: Phase NG-C

defn

ctx-subscribe

(ctx-subscribe [^borrow c : NngCtx topic : cstr] :)

add a topic prefix filter to a SUB context.

cthe context (borrowed); on anything but SUB, err NNG_ENOTSUP
topicthe byte prefix to accept; "" accepts every message

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

(ctx-subscribe c "temp:")

Since: Phase NG-C

defn

ctx-unsubscribe

(ctx-unsubscribe [^borrow c : NngCtx topic : cstr] :)

drop a topic prefix filter from a SUB context.

cthe context (borrowed)
topicthe 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