NNG_CTX_SEND(3)
π NNG_CTX_SEND(3) β nng_ctx_send π
okay bestie, welcome to the nng_ctx_send(3) page from the NNG Reference Manual β¨ this is the one where you send a message on a context and it's all async and cute π¦
πΈ NAME πΈ
nng_ctx_send β send message using context asynchronously π
β¨ SYNOPSIS β¨
#include <nng/nng.h>
void nng_ctx_send(nng_ctx ctx, nng_aio *aio);
π DESCRIPTION π
So nng_ctx_send() sends a message using the context ctx, and it does it asynchronously. no waiting around, we're busy girls π
The message you wanna send has to have been set on the aio before this β that's what nng_aio_set_msg() is for. And once you hand it over, this function assumes ownership of the message. it's not yours anymore bestie, it's the aio's now π«Ά
If the message got successfully queued for delivery to the socket, then the aio will be completed and nng_aio_result() will return zero. In that case the socket will dispose of the message itself once it's done with it. slay, no cleanup for you π
Note π The operation gets completed β and the callback associated with the aio gets executed β as soon as the socket accepts the message for sending. This does not mean the message was actually delivered!! it might still be buffered in the sending socket, buffered in the receiving socket, or literally in flight over physical media. it's giving "it's on the way, not there yet" π
If the operation fails for any reason β and yes that includes cancellation or timeout β then the aio callback will still be executed and nng_aio_result() will return a non-zero error status. In that case, it's your job (the callback's job) to retrieve the message from the aio using nng_aio_get_msg() and dispose of it appropriately. that could mean retrying the send on the same socket or a different one, or deallocating the message with nng_msg_free(). your mess, your cleanup π
Note π What "sending a message" even means varies from protocol to protocol, so please go read the protocol documentation. encouraged, even. fr fr π
Tip β Context send operations are asynchronous. If you need a synchronous one, you can construct it yourself: use aNULLcallback on theaioand then wait for the operation usingnng_aio_wait(). DIY moment π§
π₯ RETURN VALUES π₯
None. (The operation completes asynchronously.) that's it, that's the whole section β¨
π ERRORS π
NNG_ECANCELEDβ The operation was aborted. πNNG_ECLOSEDβ The contextctxis not open. πNNG_EMSGSIZEβ The message is too large. it's giving too much πNNG_ENOMEMβ Insufficient memory is available. πNNG_ENOTSUPβ The protocol for contextctxdoes not support sending. not every protocol is a sender, and that's valid πNNG_ESTATEβ The contextctxcannot send data in this state. read the room βNNG_ETIMEDOUTβ The send timeout expired. β°
π 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)
and that's the whole page babes π this was NNG Reference Manual, dated 2026-06-30, page NNG_CTX_SEND(3) β go send some messages, you absolute icon ππ¦β¨
π¦ 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