table of contents
- experimental 1.2.1+dfsg-1
NN_RECV(3) | nanomsg 1.2.1 | NN_RECV(3) |
NAME¶
nn_recv - receive a message
SYNOPSIS¶
#include <nanomsg/nn.h>
int nn_recv (int s, void *buf, size_t len, int flags);
DESCRIPTION¶
Receive a message from the socket s and store it in the buffer referenced by the buf argument. Any bytes exceeding the length specified by the len argument will be truncated.
Alternatively, nanomsg can allocate the buffer for you. To do so, let the buf parameter be a pointer to a void* variable (pointer to pointer) to the receive buffer and set the len parameter to NN_MSG. If the call is successful the user is responsible for deallocating the message using the nn_freemsg(3) function.
The flags argument is a combination of the flags defined below:
NN_DONTWAIT
RETURN VALUE¶
If the function succeeds number of bytes in the message is returned. Otherwise, -1 is returned and errno is set to to one of the values defined below.
ERRORS¶
EBADF
ENOTSUP
EFSM
EAGAIN
EINTR
ETIMEDOUT
ETERM
EXAMPLES¶
Receiving a message into a buffer allocated by the user
char buf [100]; nbytes = nn_recv (s, buf, sizeof (buf), 0);
Receiving a message into a buffer allocated by nanomsg
void *buf = NULL; nbytes = nn_recv (s, &buf, NN_MSG, 0); if (nbytes < 0) {
/* handle error */
... } else {
/* process message */
...
nn_freemsg (buf); }
Note that this can be more efficient than manually allocating a buffer since it is a zero-copy operation.
SEE ALSO¶
AUTHORS¶
Martin Sustrik <sustrik@250bpm.com>
2024-02-21 |