NNG_AIO_ALLOC(3)
π NNG_AIO_ALLOC π
okay bestie, so you know nng_aio_alloc(3) from the NNG Reference Manual? yeah, that one. it's the lil' function that makes you an asynchronous I/O handle and honestly it's giving gateway-to-everything energy. let's get into it π¦
β¨ NAME β¨
nng_aio_alloc β allocate asynchronous I/O handle. that's it, that's the whole job, and it slays π
πΈ SYNOPSIS πΈ
#include <nng/nng.h>
int nng_aio_alloc(nng_aio **aiop, void (*callb)(void *), void *arg);
look at her. three arguments. gorgeous. no notes.
π DESCRIPTION π
so here's the tea: nng_aio_alloc() allocates a handle for asynchronous I/O operations, and it stores a pointer to that handle in aiop. that's your new baby, your main character object π«Ά
the handle gets initialized with a completion callback of callb, and that callback runs when an associated asynchronous operation finishes. it gets called with the argument arg. cute, right?
β οΈ Note (this one MATTERS, no cap): the callbackcallbmust not perform any blocking operations, and it must complete its execution quickly. ifcallbdoes block, this can lead ultimately to an apparent "hang" or deadlock in your application. and yeah, that also means you should avoid operations such as allocating new objects β which, lowkey, also means opening or closing sockets, dialers, and so forth. so like... keep it light in there, bestie π
π Tip: if more complex or blocking work needs to be performed by callb, a separate thread can be used, along with a condition variable which can be signaled by the callback. that's the move. iconic.
asynchronous I/O operations all take an nng_aio handle such as the one this function allocates. and the way these usually go is: a function starts them and returns immediately (like, instantly, it does NOT wait around). the operation then runs asynchronously and completes sometime later. when it's done, the callback you supplied here gets called, and that callback is able to figure out the result of the operation using nng_aio_result(), nng_aio_count(), and nng_aio_get_output(). slay, information acquired β¨
now, plot twist: it is possible to wait synchronously for an otherwise asynchronous operation by using the function nng_aio_wait(). in that case, it is permissible for callb and arg to both be NULL. but heads up β if these are NULL, then it will not be possible to determine when the operation is complete except by calling the aforementioned nng_aio_wait(). so don't be out here wondering why nothing ever tells you anything π
π RETURN VALUES π
this function returns 0 on success, and non-zero otherwise. that's the whole vibe check.
π ERRORS π
NNG_ENOMEMβ insufficient free memory to perform the operation. your machine said "girl, no" π
π SEE ALSO π
nng_aio_abort(3), nng_aio_cancel(3), nng_aio_count(3), nng_aio_free(3), nng_aio_get_input(3), nng_aio_get_msg(3), nng_aio_get_output(3), nng_aio_result(3), nng_aio_set_input(3), nng_aio_set_iov(3), nng_aio_set_msg(3), nng_aio_set_timeout(3), nng_aio_stop(3), nng_aio_wait(3), nng_strerror(3), nng_aio(5), nng(7)
go read them all, i'll wait π§
and that's the page!! π this absolute banger of a manpage is brought to you by the NNG Reference Manual, dated 2026-06-30 β yeah, freshly stamped, still warm. periodt. πβ¨
π¦ where this page comes from
- ubuntu stonking: libnng-dev 1.12.0-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms