NN_SEND(3)

πŸ“¦
version 1.2.2 Β· 5 versions
, in fedora 44

πŸ’Œ 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 with errno set to EAGAIN. 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 β€” buf is NULL, or len is NN_MSG and the message pointer (the one buf points to) is NULL.
  • 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