No matching definitions.

nng/aio

src/nng/aio.tur

asynchronous send and receive: submit now, collect later.

Since: Phase NG-B

defopaque

Aio

(Aio)

a linear handle to one asynchronous operation slot.

Since: Phase NG-B

defn

aio-alloc

(aio-alloc :)

allocate an operation slot.

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

(let [a (ok-val (aio-alloc))]
    (recv-aio s a)
    (aio-wait a)
    (aio-free a))

Since: Phase NG-B

defn

aio-free

(aio-free [a : Aio] :)

release the slot. The single linear consumer.

athe slot, consumed
(aio-free a)

Since: Phase NG-B

defn

aio-set-timeout

(aio-set-timeout [^borrow a : Aio ms : int] :)

the deadline for this slot's later operations.

athe slot (borrowed)
msmilliseconds, or -2 / -1 / 0 as above
(aio-set-timeout a 100)

Since: Phase NG-B

defn

aio-cancel

(aio-cancel [^borrow a : Aio] :)

ask an in-flight operation to stop.

athe slot (borrowed)
(aio-cancel a)
  (aio-wait a)  ; => (err NNG_ECANCELED)

Since: Phase NG-B

defn

send-payload-aio

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

submit a send of a byte buffer.

sthe socket (borrowed)
athe slot (borrowed)
bthe payload (borrowed)

(Result nil int) -- ok: submitted, collect with aio-wait / aio-try-result / aio-poll-fd; err: nothing submitted.

(send-payload-aio s a b)

Since: Phase NG-B

defn

send-str-aio

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

submit a send of a NUL-terminated string.

sthe socket (borrowed)
athe slot (borrowed)
msgthe payload (borrowed)

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

(send-str-aio s a "job:42")

Since: Phase NG-B

defn

recv-aio

(recv-aio [^borrow s : Socket ^borrow a : Aio])

submit a receive.

sthe socket (borrowed)
athe slot (borrowed)

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

(recv-aio s a)

Since: Phase NG-B

defn

aio-wait

(aio-wait [^borrow a : Aio] :)

block until the operation finishes; its outcome.

athe slot (borrowed)

(Result nil int) -- ok, or err carrying the operation's nng error (NNG_ETIMEDOUT, NNG_ECANCELED, NNG_ECLOSED, NNG_ENOTSUP, ...).

(when (ok? (aio-wait a)) (aio-take-payload a))

Since: Phase NG-B

defn

aio-try-result

(aio-try-result [^borrow a : Aio] :)

the outcome if the operation has finished; never blocks.

athe slot (borrowed)

(Option (Result nil int)) -- (none) while in flight; (some outcome) once finished.

(match (aio-try-result a)
    (Some r) (finish r)
    (None)   (do-other-work))

Since: Phase NG-B

defn

aio-take-payload

(aio-take-payload [^borrow a : Aio] :)

the received message, as an owned Payload.

athe slot (borrowed)

(Result Payload int) -- ok: a fresh Payload the caller releases with payload-free; err: the receive's own error, or NNG_ESTATE when there is nothing to take (not a receive, still in flight, already taken).

(let [r (aio-take-payload a)]
    (when (ok? r) (do (use (ok-val r)) (payload-free (ok-val r)))))

Since: Phase NG-B

defn

aio-take-str

(aio-take-str [^borrow a : Aio] :)

the received message, as a malloc'd cstr.

athe slot (borrowed)

(Result cstr int) -- ok: a fresh string the caller frees; err as for aio-take-payload.

(println (ok-val (aio-take-str a)))

Since: Phase NG-B

defn

aio-poll-fd

(aio-poll-fd [^borrow a : Aio] :)

an fd that is readable while a finished operation awaits collection.

athe slot (borrowed)

(Result PollFd int) -- err carries NNG_ENOMEM if the pipe could not be made.

(local-park-fd g (poll-fd->int (ok-val (aio-poll-fd a))) READ 2000)

Since: Phase NG-B