NNG_CTX_RECV(3)
π NNG_CTX_RECV π
okay bestie, welcome to the nng_ctx_recv page from the NNG Reference Manual π β this is the one where you get messages through a context and everything happens asynchronously, which is a fancy way of saying "don't wait around, girl, the callback will text you back" π
β¨ NAME β¨
nng_ctx_recv β receive a message using a context, asynchronously π¦
β¨ SYNOPSIS β¨
#include <nng/nng.h>
void nng_ctx_recv(nng_ctx ctx, nng_aio *aio);
β¨ DESCRIPTION β¨
So like. nng_ctx_recv() receives a message using the context ctx, and it does it asynchronously β no blocking, no waiting, main character energy only π
When a message gets successfully received by the context, it's stashed into the aio by an internal call that's equivalent to nng_aio_set_msg(), and then the completion callback on the aio runs. In that happy little case, nng_aio_result() returns zero. And it's literally your job β the callback function's job β to go grab that message and dispose of it properly. That's the whole assignment. π
IMPORTANT, fr fr π Failing to accept and dispose of messages in this case can lead to memory leaks. Not cute. Not slay. Just leak. So please actually take the message, bestie π
If for some reason the async receive can't complete successfully β and yes, that includes it being canceled or timing out β the callback still runs, but nng_aio_result() will be non-zero. She still shows up to the party, she's just bringing bad news π
Note π What "receiving a message" even means varies from protocol to protocol, so please go read the protocol documentation too. It's giving "context matters." Examined. Encouraged. πΈ
β¨ RETURN VALUES β¨
None. Because the operation completes asynchronously β nothing to return, it's all vibes and callbacks β¨
β¨ ERRORS β¨
NNG_ECANCELEDβ bestie the operation was aborted πNNG_ECLOSEDβ the context ctx is not open. Door's shut, girl πͺNNG_ENOMEMβ not enough memory available. The RAM said no πNNG_ENOTSUPβ the protocol for context ctx does not support receiving. Not every protocol wants to catch these messages πNNG_ESTATEβ the context ctx cannot receive data in this state. Wrong era, wrong state, wrong vibe check π¦NNG_ETIMEDOUTβ the receive timeout expired. She waited, she left β
β¨ SEE ALSO β¨
nng_aio_get_msg(3), nng_aio_set_msg(3), nng_msg_alloc(3), nng_strerror(3), nng_aio(5), nng_ctx(5), nng_msg(5), nng(7)
okay that's the whole page, you ate that π go forth and receive your messages responsibly, dispose of them, and do not leak memory, that's the bare minimum π«Ά
signing off with the tea β: this one's from the NNG Reference Manual, dated 2026-06-30, and yeah β that's the same day as the page header said. 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