NNG_CTX_SEND(3)

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

πŸ’– 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 a NULL callback on the aio and then wait for the operation using nng_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 context ctx is 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 context ctx does not support sending. not every protocol is a sender, and that's valid πŸ’…
  • NNG_ESTATE β€” The context ctx cannot 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