1NN_RECVMSG(3) nanomsg 1.1.5 NN_RECVMSG(3)
2
3
4
6 nn_recvmsg - fine-grained alternative to nn_recv
7
9 #include <nanomsg/nn.h>
10
11 NN_EXPORT int nn_recvmsg (int s, struct nn_msghdr *msghdr, int flags);
12
14 Receives a message from socket s into buffers specified by msghdr
15 parameter along with any additional control data. msghdr parameter
16 should be nullified before being used.
17
18 Structure nn_msghdr contains at least following members:
19
20 struct nn_iovec *msg_iov;
21 int msg_iovlen;
22 void *msg_control;
23 size_t msg_controllen;
24
25 msg_iov points to a gather array of buffers to fill in. msg_iovlen
26 specifies the size of the array.
27
28 msg_control points to the buffer to hold control information
29 associated with the received message. msg_controllen specifies the
30 length of the buffer. If the control information should not be
31 retrieved, set msg_control parameter to NULL. For detailed discussion
32 of how to parse the control information check nn_cmsg(3) man page.
33
34 Structure nn_iovec defines one element in the gather array (a buffer to
35 be filled in by message data) and contains following members:
36
37 void *iov_base;
38 size_t iov_len;
39
40 Alternatively, nanomsg library can allocate the buffer for you. To do
41 so, let the iov_base point to void* variable to receive the buffer and
42 set iov_len to NN_MSG. After successful completion user is responsible
43 for deallocating the message using nn_freemsg(3) function. Gather array
44 in nn_msghdr structure can contain only one element in this case.
45
46 The flags argument is a combination of the flags defined below:
47
48 NN_DONTWAIT
49 Specifies that the operation should be performed in non-blocking
50 mode. If the message cannot be received straight away, the function
51 will fail with errno set to EAGAIN.
52
54 If the function succeeds number of bytes in the message is returned.
55 Otherwise, -1 is returned and errno is set to to one of the values
56 defined below.
57
59 EBADF
60 The provided socket is invalid.
61
62 ENOTSUP
63 The operation is not supported by this socket type.
64
65 EFSM
66 The operation cannot be performed on this socket at the moment
67 because socket is not in the appropriate state. This error may
68 occur with socket types that switch between several states.
69
70 EAGAIN
71 Non-blocking mode was requested and there’s no message to receive
72 at the moment.
73
74 EINTR
75 The operation was interrupted by delivery of a signal before the
76 message was received.
77
78 ETIMEDOUT
79 Individual socket types may define their own specific timeouts. If
80 such timeout is hit this error will be returned.
81
82 ETERM
83 The library is terminating.
84
86 struct nn_msghdr hdr;
87 struct nn_iovec iov [2];
88 char buf0 [4];
89 char buf1 [2];
90 iov [0].iov_base = buf0;
91 iov [0].iov_len = sizeof (buf0);
92 iov [1].iov_base = buf1;
93 iov [1].iov_len = sizeof (buf1);
94 memset (&hdr, 0, sizeof (hdr));
95 hdr.msg_iov = iov;
96 hdr.msg_iovlen = 2;
97 nn_recvmsg (s, &hdr, 0);
98
100 nn_recv(3) nn_sendmsg(3) nn_allocmsg(3) nn_freemsg(3) nn_cmsg(3)
101 nanomsg(7)
102
104 Martin Sustrik <sustrik@250bpm.com>
105
106
107
108 2021-07-22 NN_RECVMSG(3)