'\" t .\" Title: nng_recv .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.23 .\" Date: 2025-02-02 .\" Manual: NNG Reference Manual .\" Source: \ \& .\" Language: English .\" .TH "NNG_RECV" "3" "2025-02-02" "\ \&" "NNG Reference Manual" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 .nh .ad l .de URL \fI\\$2\fP <\\$1>\\$3 .. .als MTO URL .if \n[.g] \{\ . mso www.tmac . am URL . ad l . . . am MTO . ad l . . . LINKSTYLE blue R < > .\} .SH "NAME" nng_recv \- recv data .SH "SYNOPSIS" .sp .if n .RS 4 .nf .fam C #include <nng/nng.h> int nng_recv(nng_socket s, void *data, size_t *sizep, int flags); .fam .fi .if n .RE .SH "DESCRIPTION" .sp The \f(CRnng_recv()\fP receives a message. .sp The \fIflags\fP is a bit mask that may contain any of the following values: .sp \f(CRNNG_FLAG_NONBLOCK\fP .RS 4 The function returns immediately, even if no message is available. Without this flag, the function will wait until a message is received by the socket \fIs\fP, or any configured timer expires. .RE .sp \f(CRNNG_FLAG_ALLOC\fP .RS 4 If this flag is present, then a zero\-copy mode is used. In this case the caller must set the value of \fIdata\fP to the location of another pointer (of type \f(CRvoid *\fP), and the \fIsizep\fP pointer must be set to a location to receive the size of the message body. The function will then allocate a message buffer (as if by \f(CRnng_alloc()\fP), fill it with the message body, and store it at the address referenced by \fIdata\fP, and update the size referenced by \fIsizep\fP. The caller is responsible for disposing of the received buffer either by the \f(CRnng_free()\fP function or passing the message (also with the \f(CRNNG_FLAG_ALLOC\fP flag) in a call to \f(CRnng_send()\fP. .RE .sp If the special flag \f(CRNNG_FLAG_ALLOC\fP (see above) is not specified, then the caller must set \fIdata\fP to a buffer to receive the message body content, and must store the size of that buffer at the location pointed to by \fIsizep\fP. When the function returns, if it is successful, the size at \fIsizep\fP will be updated with the actual message body length copied into \fIdata\fP. .if n .sp .RS 4 .it 1 an-trap .nr an-no-space-flag 1 .nr an-break-flag 1 .br .ps +1 .B Note .ps -1 .br .sp The \f(CRNNG_FLAG_ALLOC\fP flag is deprecated and may be removed in a future release. Applications should use \f(CRnng_recvmsg()\fP for zero copy performance improvements. .sp .5v .RE .if n .sp .RS 4 .it 1 an-trap .nr an-no-space-flag 1 .nr an-break-flag 1 .br .ps +1 .B Note .ps -1 .br .sp The semantics of what receiving a message means vary from protocol to protocol, so examination of the protocol documentation is encouraged. (For example, with a \fIreq\fP socket a message may only be received after a request has been sent, and a \fIsub\fP socket may only receive messages corresponding to topics to which it has subscribed.) Furthermore, some protocols may not support receiving data at all, such as \fIpub\fP. .sp .5v .RE .SH "RETURN VALUES" .sp This function returns 0 on success, and non\-zero otherwise. .SH "ERRORS" .sp \f(CRNNG_EAGAIN\fP .RS 4 The operation would block, but \f(CRNNG_FLAG_NONBLOCK\fP was specified. .RE .sp \f(CRNNG_ECLOSED\fP .RS 4 The socket \fIs\fP is not open. .RE .sp \f(CRNNG_EINVAL\fP .RS 4 An invalid set of \fIflags\fP was specified. .RE .sp \f(CRNNG_EMSGSIZE\fP .RS 4 The received message did not fit in the size provided. .RE .sp \f(CRNNG_ENOMEM\fP .RS 4 Insufficient memory is available. .RE .sp \f(CRNNG_ENOTSUP\fP .RS 4 The protocol for socket \fIs\fP does not support receiving. .RE .sp \f(CRNNG_ESTATE\fP .RS 4 The socket \fIs\fP cannot receive data in this state. .RE .sp \f(CRNNG_ETIMEDOUT\fP .RS 4 The operation timed out. .RE .SH "SEE ALSO" .sp nng_alloc(3), nng_free(3), nng_recvmsg(3), nng_send(3), nng_strerror(3), nng(7)