NNG_CTX_RECV(3)

πŸ“¦
version 1.12.0 Β· 4 versions
, in ubuntu stonking

πŸ’– 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