NN_RECV(3compat)
π
NN_RECV(3compat) β like, the whole nn_recv situation
okay so bestie, welcome to the NNG Reference Manual, 3compat girlie edition. this one's about receiving data with the compatible API β legacy vibes, but we're gonna make it make sense fr fr π«Ά
β¨ NAME
nn_recv β receive data (compatible API). that's it, that's the whole vibe π
β¨ SYNOPSIS
#include <nanomsg/nn.h>
int nn_recv(int sock, void *data, size_t size, int flags)
put that in your code and slay β¨
β¨ DESCRIPTION
so nn_recv() receives a message from the socket sock. the message body has to fit inside size bytes, and it gets stored at whatever location data points to β unless size is the special value NN_MSG, which means zero-copy mode is happening π
note note note π β this function exists for API compatibility with legacy libnanomsg. consider using the relevant modern API instead. like, she's iconic but she's a legacy queen, iykyk.
okay so if size has that special value NN_MSG, then a zero-copy operation is performed. in that case, instead of copying the message data into the address specified by data, a brand new message big enough to hold the message data gets allocated (as if by the function nn_allocmsg()), and the message payload is stored accordingly. so in this case, the value stored at data is not the message data β it's a pointer to the message itself π¦
and in that case, on success, the caller shall take responsibility for the final disposition of the message β like, such as by sending it to another peer using nn_send(), or by nn_freemsg(). take care of your message bestie, she's yours now π
the flags field may contain the special flag NN_DONTWAIT. in that case, if no message is available for immediate receipt, the operation shall not block β instead it will fail with the error EAGAIN. no waiting around, main character energy β
β¨ RETURN VALUES
this function returns the number of bytes sent on success, and -1 on error. (yes, "sent" β that's what the page says, don't come for me π that's the documented wording, fr fr.)
β¨ ERRORS
EAGAINβ the operation would block. bestie said not today βEBADFβ the socketsockis not open. like girl, open it first πEFSMβ the socket cannot receive in this state. wrong state, wrong era πENOTSUPβ this protocol cannot receive. not every protocol is built for this πETIMEDOUTβ operation timed out. the clock ran out, sad but true π
β¨ SEE ALSO
nn_errno(3compat), nn_recvmsg(3compat), nn_send(3compat), nn_socket(3compat), nn_compat(3compat), nng(7) β go read the whole friend group π
that's the page, babe π written from the NNG Reference Manual and dated 2026-01-13, so you know exactly which version of the lore you're reading. go receive some messages and be iconic about it. periodt ππ π₯
π¦ 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