NNG_RECV(3)
β¨ NAME β¨
nng_recv β recv data π (like, it receives a message, that's the whole job, and it eats every time)
This is the nng_recv page from the NNG Reference Manual, section 3, so if you're here you're probably trying to scoop a message out of a socket. Say less bestie, I got you π«Ά
πΈ SYNOPSIS πΈ
#include <nng/nng.h>
int nng_recv(nng_socket s, void *data, size_t *sizep, int flags);
π DESCRIPTION π
okay so nng_recv() receives a message. That's it, that's the vibe, that's the whole function β¨
The flags is a bit mask, which is just fancy talk for "you can stack these lil guys together with |" β and it may contain any of the following values:
NNG_FLAG_NONBLOCKβ bestie the function bails immediately, even if there's literally no message waiting for you. Without this flag? It's gonna sit there and wait until a message gets received by sockets, or until some configured timer runs out. Patient queen behavior β³NNG_FLAG_ALLOCβ if this flag is present, then a zero-copy mode is used. In that case the caller must set the value ofdatato the location of another pointer (of typevoid *), and thesizeppointer must be set to a location to receive the size of the message body. Then the function will allocate a message buffer (as if bynng_alloc()), fill it with the message body, and store it at the address referenced bydata, and update the size referenced bysizep. And now the caller is responsible for disposing of the received buffer either by thenng_free()function or by passing the message (also with theNNG_FLAG_ALLOCflag) in a call tonng_send(). Your buffer, your responsibility, no cap π
If the special flag NNG_FLAG_ALLOC (see above, it's the second one π) is not specified, then the caller must set data to a buffer to receive the message body content, and must store the size of that buffer at the location pointed to by sizep. When the function returns, if it is successful, the size at sizep will be updated with the actual message body length copied into data. So you hand it a bucket, it tells you how full the bucket got πͺ£
Note π TheNNG_FLAG_ALLOCflag is deprecated and may be removed in a future release. Applications should usenng_recvmsg()for zero copy performance improvements. Ma'am that flag is on thin ice, use the other one π
Note π The semantics of what receiving a message means vary from protocol to protocol, so examination of the protocol documentation is encouraged. Like, for example, with areqsocket a message may only be received after a request has been sent, and asubsocket may only receive messages corresponding to topics to which it has subscribed. Every protocol has its own rules, it's giving β¨ lore β¨. Furthermore, some protocols may not support receiving data at all, such aspub. yeah, that one's just here to talk, not to listen π
π₯ RETURN VALUES π₯
This function returns 0 on success, and non-zero otherwise. Zero is the slay outcome, anything else means something went sideways π«
π ERRORS π
NNG_EAGAINβ the operation would block, butNNG_FLAG_NONBLOCKwas specified. You asked it not to wait and it had nothing to give, so.NNG_ECLOSEDβ the socketsis not open. She's gone, bestie πͺNNG_EINVALβ an invalid set of flags was specified. You mixed a combo that doesn't exist π¬NNG_EMSGSIZEβ the received message did not fit in the size provided. Too big for the bucket πNNG_ENOMEMβ insufficient memory is available. The machine is full π΅NNG_ENOTSUPβ the protocol for socketsdoes not support receiving. It said "not my job" πNNG_ESTATEβ the socketscannot receive data in this state. Wrong moment, wrong state, wrong everything.NNG_ETIMEDOUTβ the operation timed out. You waited, the vibe expired β°
π¦ SEE ALSO π¦
okay that's the whole page bestie, you're officially certified in receiving messages πβ¨ this was NNG_RECV(3) from the NNG Reference Manual, dated 2026-06-30 β go forth, receive responsibly, and remember to free your buffers πππ«Ά
π¦ where this page comes from
- ubuntu stonking: libnng-dev 1.12.0-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms