NNG_SEND(3)
π NNG_SEND(3) β bestie, we're sending data π
okay so this is a page from the NNG Reference Manual and honestly? she's a classic. sit down, grab a strawberry drink π, and let's talk about nng_send.
β¨ NAME β¨
nng_send β send data. that's it. that's the whole vibe. π€
π¦ SYNOPSIS π¦
#include <nng/nng.h>
int nng_send(nng_socket s, void *data, size_t size, int flags);
look at her. four params. no drama. no cap.
π DESCRIPTION π
so nng_send() sends a message that contains the data of length size, using the socket s. like, you hand her your bytes and she ships them. π
Note π
the semantics of what "sending a message" even means changes from protocol to protocol, so pls pls pls go read the protocol documentation, it's giving required reading. for example, with a pub socket the data gets broadcast, so any peers who have a suitable subscription will be able to receive it using nng_recv() or a similar function. and some protocols straight up don't support sending (looking at you, sub π) or they need other conditions met first. for example, rep sockets cannot normally send data β which in their case are responses to requests β until they have first received a request. she has β¨rulesβ¨.
the flags may contain either of (or neither of) the following values:
NNG_FLAG_NONBLOCKβ the function returns immediately, no matter whether the socket is able to accept the data or not. if the socket can't accept it (like if backpressure exists because the peers are consuming messages too slowly, or there's no peer present at all π), then the function will return withNNG_EAGAIN. if you don't specify this flag, then the function will block if such a condition exists. so likeβ¦ choose your fighter.NNG_FLAG_ALLOCβ this one means the data was allocated usingnng_alloc(), or was obtained from a call tonng_recv()with theNNG_FLAG_ALLOCflag. if this function returns success, then the data is "owned" by the function, and it will assume responsibility for callingnng_free()when it is no longer needed. if this flag is absent, the data is copied by the implementation before the function returns to the caller. copy queen behavior, honestly.
Note β οΈ theNNG_FLAG_ALLOCflag is deprecated and may be removed in a future release. applications should usenng_sendmsg()for zero copy performance improvements. ok so like, dead flag walking, use the new one bestie.
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. it's giving "sent into the void, hope it lands" π
Important π₯π₯π₯ when usingNNG_FLAG_ALLOC, it is important that the value ofsizematch the actual allocated size of the data. using an incorrect size results in unspecified behavior, which may include heap corruption, program crashes, or trans-dimensional mutation of the program's author. yeah. yoursizeoff by one and suddenly you're a different person in a different dimension. not the glow-up you asked for. β οΈ
π 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. you asked her not to wait and she was NOT about to wait.NNG_ECLOSEDβ the socketsis not open. she's gone, babes.NNG_EINVALβ an invalid set of flags was specified. bad flags. no. πNNG_EMSGSIZEβ the value ofsizeis too large. chill, that's too much.NNG_ENOMEMβ insufficient memory is available. she's full, there's literally no room.NNG_ENOTSUPβ the protocol for socketsdoes not support sending. wrong protocol for this, bestie.NNG_ESTATEβ the socketscannot send data in this state. she's just not in the mood right now.NNG_ETIMEDOUTβ the operation timed out. she waited, you didn't show. π
π«Ά SEE ALSO π«Ά
nng_alloc(3), nng_free(3), nng_recv(3), nng_sendmsg(3), nng_strerror(3), nng_socket(5), nng(7)
go read those too, iykyk π
and that's the whole page, bestie!! this was the NNG Reference Manual entry for NNG_SEND(3), and the footer energy is giving 2026-06-30 β so yeah, she's dated, she's official, and she ate. π
β¨ππ¦
π¦ 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