NN_SEND(3compat)

πŸ“¦ version 1.11, in alpine 3.24

πŸ’Œ NN_SEND(3compat) β€” the nng girlie's guide

okay bestie, welcome to the NNG Reference Manual corner of the group chat, where we're talking about nn_send from the 3compat era. yes she's a legacy queen but she still serves πŸ’…


✨ NAME ✨

nn_send β€” send data (compatible API). that's it, that's the vibe πŸŽ€


🌸 SYNOPSIS 🌸

#include <nanomsg/nn.h>

int nn_send(int sock, const void *data, size_t size, int flags)

look at her. gorgeous. iconic. five whole arguments πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

so nn_send() literally creates a message containing data (of size size), and sends it using the socket sock. that's the whole job, and she does it slayfully ✨

🫢 note, bestie: this function is here for API compatibility with legacy libnanomsg. consider using the relevant modern API instead β€” like, she's the friend you still love but who's kind of from 2014. no cap.

πŸ’« the zero-copy situation

if size has the special value NN_MSG, then a zero-copy operation is performed. and this is where it gets a little spicy 😭 in this case data does not point to the message content itself β€” instead it's a pointer to the pointer, an extra level of pointer indirection. yes, pointer-to-pointer. she's giving inception.

the message must have been previously allocated by nn_allocmsg() or nn_recvmsg(), using the same NN_MSG size. and listen β€” in this case the ownership of the message shall remain with the caller, unless the function returns 0, which indicates that the function has taken responsibility for delivering or disposing of the message. so like, read the return value before you go touching that memory again πŸ™ˆ

πŸŽ€ the flags field

the flags field may contain the special flag NN_DONTWAIT. in this case, if the socket is unable to accept more data for sending, the operation shall not block, but instead will fail with the error EAGAIN. she said "i'm not waiting around" πŸ’…

⚠️ another note, and this one matters: the send operation is performed asynchronously, and may not have completed before this function returns control to the caller. so don't go assuming it's done-done just because she came back to you, okay? 🫢

πŸ‘‘ RETURN VALUES πŸ‘‘

this function returns the number of bytes sent on success, and -1 on error. simple. elegant. main character energy ⭐


πŸ’€ ERRORS πŸ’€

  • EAGAIN β€” the operation would block. (she's busy, try again later)
  • EBADF β€” the socket sock is not open. (bestie that socket does not exist 😭)
  • EFSM β€” the socket cannot send in this state. (wrong state, wrong time)
  • ENOTSUP β€” this protocol cannot send. (not every protocol has the range, and that's valid)
  • ETIMEDOUT β€” operation timed out. (she took too long, we're moving on πŸ•)

🌈 SEE ALSO 🌈

nn_errno(3compat), nn_recv(3compat), nn_sendmsg(3compat), nn_socket(3compat), nn_compat(3compat), nng(7)

the whole friend group fr fr 🫢 go read them, iykyk


and that's the page, babe πŸ’œ big sign-off energy: this was the NNG Reference Manual, dated 2026-01-13 β€” mwah, go send some messages, you're gonna ate πŸ¦‹βœ¨

πŸ“¦ where this page comes from