NN_SEND(3compat)
π 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 socketsockis 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
- alpine 3.24: nng-doc 1.11-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms