NN_RECV(3compat)

πŸ“¦ version 1.11, in alpine 3.24

πŸ’… 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 socket sock is 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