NNG_SENDMSG(3)
π NNG_SENDMSG(3) β the nng_sendmsg girlies' guide
okay so bestie, we're in the NNG Reference Manual and today's main character is nng_sendmsg, aka "send a whole message, not just some bytes." pull up a chair, grab a strawberry π, let's go.
β¨ NAME β¨
nng_sendmsg β send message π
πΈ SYNOPSIS πΈ
#include <nng/nng.h>
int nng_sendmsg(nng_socket s, nng_msg *msg, int flags);
π¦ DESCRIPTION π¦
nng_sendmsg() sends the message msg using the socket s. that's it, that's the vibe. β¨
Now here's the part you actually need to internalize, because it's giving ownership handoff:
- if the function returns zero, meaning it has accepted the message for delivery, then
msgis owned by the sockets, and you β the caller β must not make any further use of it. the socket will free the message when it's finished with it. so like, hands off, ok? π - if the function returns non-zero, then it's your responsibility to dispose of
msg. that disposal can be freeing it, sending it to another socket, or simply trying again later. it's your message again, bestie, you got custody. π«Ά
Tip π‘ Using this function gives you access to the message structure, and it may offer more functionality than the simpler nng_send() function.
Note π The semantics of what sending a message actually means vary from protocol to protocol, so examination of the protocol documentation is encouraged. (for example, with apubsocket the data is broadcast, so that any peers who have a suitable subscription will be able to receive it usingnng_recv()or a similar function.) Furthermore, some protocols may not support sending (such assub) or may require other conditions. (for example,repsockets cannot normally send data, which are responses to requests, until they have first received a request.) like, the protocol has β¨loreβ¨ and you need to read it.
The flags may contain the following value:
NNG_FLAG_NONBLOCKβ the function returns immediately, regardless of whether the socket is able to accept the data or not. If the socket is unable to accept the data (such as if backpressure exists because the peers are consuming messages too slowly, or no peer is present), then the function will return withNNG_EAGAIN. If this flag is not specified, then the function will block if such a condition exists. π΄
Note π Regardless of the presence or absence ofNNG_FLAG_NONBLOCK, there may be queues between the sender and the receiver. Furthermore, there is no guarantee that the message has actually been delivered. Finally, with some protocols, the semantic is implicitlyNNG_FLAG_NONBLOCK, such as withpubsockets, which are best-effort delivery only. no cap, "sent" does not always mean "received." π
π RETURN VALUES π
This function returns 0 on success, and non-zero otherwise. simple. iconic. periodt.
π ERRORS π
NNG_EAGAINβ The operation would block, butNNG_FLAG_NONBLOCKwas specified.NNG_ECLOSEDβ The socketsis not open.NNG_EINVALβ An invalid set of flags was specified.NNG_EMSGSIZEβ The value ofsizeis too large.NNG_ENOMEMβ Insufficient memory is available.NNG_ENOTSUPβ The protocol for socketsdoes not support sending.NNG_ESTATEβ The socketscannot send data in this state.NNG_ETIMEDOUTβ The operation timed out.
π SEE ALSO π
nng_msg_alloc(3), nng_recvmsg(3), nng_send(3), nng_strerror(3), nng_msg(5), nng_socket(5), nng(7)
okay that's the whole page!! go forth and send your messages (and respect the ownership rules, fr fr, or you WILL double-free and it will be giving undefined behavior energy π). mwah π
this was NNG_SENDMSG(3), from the NNG Reference Manual, dated 2026-06-30 β love you, bye bestie! π§β¨
π¦ 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