NNG_SENDMSG(3)

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

πŸ’Œ 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 msg is owned by the socket s, 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 a pub socket the data is broadcast, so that any peers who have a suitable subscription will be able to receive it using nng_recv() or a similar function.) Furthermore, some protocols may not support sending (such as sub) or may require other conditions. (for example, rep sockets 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 with NNG_EAGAIN. If this flag is not specified, then the function will block if such a condition exists. 😴
Note πŸ‘ Regardless of the presence or absence of NNG_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 implicitly NNG_FLAG_NONBLOCK, such as with pub sockets, 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, but NNG_FLAG_NONBLOCK was specified.
  • NNG_ECLOSED β€” The socket s is not open.
  • NNG_EINVAL β€” An invalid set of flags was specified.
  • NNG_EMSGSIZE β€” The value of size is too large.
  • NNG_ENOMEM β€” Insufficient memory is available.
  • NNG_ENOTSUP β€” The protocol for socket s does not support sending.
  • NNG_ESTATE β€” The socket s cannot 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