NN_SEND(3)
π NN_SEND(3) β the nanomsg page, bestie edition
okay so real quick: this is nn_send(3) from nanomsg 1.2.2, and it's literally the "yeet a message into the void (but like, a targeted void)" function. pull up a chair, we're doing this together π«Ά
β¨ NAME β¨
nn_send β send a message π
πΈ SYNOPSIS πΈ
#include <nanomsg/nn.h>
int nn_send (int s, const void *buf, size_t len, int flags);
π¦ DESCRIPTION π¦
so the vibe is: this function sends a message made of the data sitting in the buffer that buf points at, out through the socket s. that message is gonna be exactly len bytes long. periodt.
β¨ plot twist option β¨ β if you'd rather send a buffer that was allocated by nn_allocmsg(3), you do it differently: point buf at the pointer to the buffer, and set len to the NN_MSG constant. in that case, a successful nn_send call deallocates the buffer for you. and bestie, listen to me: if you try to deallocate it yourself afterwards, that's undefined behaviour. not cute. do not.
which of the peers actually receives your message? that's not up to this function β it's determined by the particular socket type. iykyk π«
the flags argument is a combination of the flags listed below:
NN_DONTWAITβ says "do this in non-blocking mode, pls". if the message can't be sent straight away, the function will fail witherrnoset toEAGAIN. no waiting, no patience, we move π¨
π RETURN VALUE π
if it works? you get back the number of bytes in the message. slay.
if it doesn't? you get -1, and errno is set to one of the values down below. π
π₯ ERRORS π₯
EFAULTβbufisNULL, orlenisNN_MSGand the message pointer (the onebufpoints to) isNULL.EBADFβ the socket you handed over is invalid. not a real socket, bestie.ENOTSUPβ this socket type just doesn't support this operation. it's not you, it's the socket.EFSMβ the operation can't happen right now because the socket isn't in the right state. this one shows up with socket types that switch between several states β main character energy, honestly.EAGAINβ non-blocking mode was requested and the message can't be sent at the moment.EINTRβ a signal showed up mid-operation and interrupted it before the message was sent. rude.ETIMEDOUTβ individual socket types may define their own specific timeouts. if such a timeout gets hit, you get this error.ETERMβ the library is terminating. it's over, we're done here π
π EXAMPLE π
using data directly:
nbytes = nn_send (s, "ABC", 3, 0);
assert (nbytes == 3);
using a pre-allocated message buffer:
void *msg = nn_allocmsg(3, 0);
strncpy(msg, "ABC", 3);
nbytes = nn_send (s, &msg, NN_MSG, 0);
assert (nbytes == 3);
notice how the second one passes &msg and NN_MSG? yeah. that's the whole bit. π
π SEE ALSO π
π§ AUTHORS π§
Martin Sustrik <sustrik@250bpm.com>
β and that's the whole page, no cap. go forth and send responsibly, my love π«Ά
this has been NN_SEND(3) from nanomsg 1.2.2, dated 2026-01-16. mwah. π
π¦ where this page comes from
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms