NNG_SEND(3)

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

πŸ’Œ 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 with NNG_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 using nng_alloc(), or was obtained from a call to nng_recv() with the NNG_FLAG_ALLOC flag. if this function returns success, then the data is "owned" by the function, and it will assume responsibility for calling nng_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 ⚠️ the NNG_FLAG_ALLOC flag is deprecated and may be removed in a future release. applications should use nng_sendmsg() for zero copy performance improvements. ok so like, dead flag walking, use the new one bestie.
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. it's giving "sent into the void, hope it lands" πŸ’€
Important πŸ”₯πŸ”₯πŸ”₯ when using NNG_FLAG_ALLOC, it is important that the value of size match 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. your size off 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, but NNG_FLAG_NONBLOCK was specified. you asked her not to wait and she was NOT about to wait.
  • NNG_ECLOSED β€” the socket s is not open. she's gone, babes.
  • NNG_EINVAL β€” an invalid set of flags was specified. bad flags. no. πŸ™ˆ
  • NNG_EMSGSIZE β€” the value of size is 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 socket s does not support sending. wrong protocol for this, bestie.
  • NNG_ESTATE β€” the socket s cannot 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