/usr/share/doc/libnanomsg-dev/nn_recv.txt is in libnanomsg-dev 0.8~beta+dfsg-1+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | 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 linknanomsg:nn_freemsg[3] function.
The 'flags' argument is a combination of the flags defined below:
*NN_DONTWAIT*::
Specifies that the operation should be performed in non-blocking mode. If the
message cannot be received straight away, the function will fail with 'errno'
set to EAGAIN.
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*::
The provided socket is invalid.
*ENOTSUP*::
The operation is not supported by this socket type.
*EFSM*::
The operation cannot be performed on this socket at the moment because socket is
not in the appropriate state. This error may occur with socket types that
switch between several states.
*EAGAIN*::
Non-blocking mode was requested and there's no message to receive at the moment.
*EINTR*::
The operation was interrupted by delivery of a signal before the message was
received.
*ETIMEDOUT*::
Individual socket types may define their own specific timeouts. If such timeout
is hit this error will be returned.
*ETERM*::
The library is terminating.
EXAMPLES
--------
Receiving a message into a buffer allocated by the user::
This example code will retrieve a message of either 100 bytes or less. If a
larger message was sent it will be truncated to 100 bytes.
----
char buf [100];
nbytes = nn_recv (s, buf, sizeof (buf), 0);
----
Receiving a message into a buffer allocated by _nanomsg_::
The following will get a message from the pipe with a buffer allocated by
the system. It is large enough to accommodate the entire message. This is a good
way to get the entire message without truncating if the size of the message is
unknown. It is the user's responsibility to call linknanomsg:nn_freemsg[3] after
processing the message.
----
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
--------
linknanomsg:nn_send[3]
linknanomsg:nn_recvmsg[3]
linknanomsg:nn_socket[3]
linknanomsg:nanomsg[7]
AUTHORS
-------
Martin Sustrik <sustrik@250bpm.com>
|