NNG_RECV_AIO(3)
π nng_recv_aio(3) β bestie's guide to grabbing messages async
okay so this is a page from the NNG Reference Manual. yes THE nng manual. and today we're talking about nng_recv_aio β receiving messages, but make it β¨asynchronousβ¨. iykyk.
πΈ NAME πΈ
nng_recv_aio β receive message asynchronously β¨
π SYNOPSIS π
#include <nng/nng.h>
void nng_recv_aio(nng_socket s, nng_aio *aio);
like, that's it. two args. void return. she's simple, she's iconic.
π¦ DESCRIPTION π¦
so the way that nng_recv_aio() works is: it receives a message using the socket s, but it does it asynchronously. no blocking, no waiting around, we're busy and booked.
when a message actually lands on the socket, it gets stashed in the aio β and the way that happens is an internal call that's equivalent to nng_aio_set_msg(). then the completion callback on the aio fires. and in this case nng_aio_result() returns zero π. the callback function is the one responsible for grabbing that message and disposing of it properly. that's on you, bestie.
β οΈ Important β not me being dramatic but: if you fail to accept and dispose of messages in this case, you can get memory leaks. like, actual leaks. your process will just be sitting there holding memory forever. no cap. dispose of your messages. periodt.
and listen β if for some reason the async receive cannot complete successfully (and yes that includes getting canceled, or timing out π), then the callback STILL gets executed. but nng_aio_result() will be non-zero. so check it!! always check it!!
π Note β the semantics of what "receiving a message" even means varies from protocol to protocol, so like, go read the protocol documentation, it's encouraged, it's giving homework but it's important. for example: with apubsocket the data is broadcast, so any peers who have a suitable subscription will be able to receive it usingnng_recv()or a similar function. also some protocols may just straight up not support receiving (likepub, she doesn't do that) or may require other conditions. for example,reqsockets cannot normally receive data (which are the replies to requests) until they have first sent a request. so like, order of operations matters, bestie.
π RETURN VALUES π
None. because the operation completes asynchronously. she doesn't return, she arrives. πβοΈ
π ERRORS π
these are the ways it can go wrong. know them. respect them.
NNG_ECANCELEDβ the operation was aborted. she said no thank you πNNG_ECLOSEDβ the socketsis not open. bestie the door is closed.NNG_ENOMEMβ insufficient memory is available. the vibes are out of RAM πNNG_ENOTSUPβ the protocol for socketsdoes not support receiving. not every protocol does recv, and that's okay, we don't shame.NNG_ESTATEβ the socketscannot receive data in this state. wrong place, wrong time fr fr.NNG_ETIMEDOUTβ the receive timeout expired. clock ran out. β°
π₯ SEE ALSO π₯
nng_aio_get_msg(3)nng_aio_set_msg(3)nng_msg_alloc(3)nng_strerror(3)nng_aio(5)nng_msg(5)nng_socket(5)nng(7)
and that's the whole page bestie, every last option, every error, every cross-reference, untouched and immaculate π
mwah π this was the NNG Reference Manual, dated 2026-06-30. go forth and dispose of your messages properly. slay. π«Ά
π¦ 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