1NN_SENDMSG(3) nanomsg 1.1.5 NN_SENDMSG(3)
2
3
4
6 nn_sendmsg - fine-grained alternative to nn_send
7
9 #include <nanomsg/nn.h>
10
11 int nn_sendmsg (int s, const struct nn_msghdr *msghdr, int flags);
12
14 Sends data specified by msghdr parameter to socket s along with any
15 additional control data. msghdr structure should be nullified before
16 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 scatter array of buffers to send. msg_iovlen
26 specifies the size of the array.
27
28 msg_control points to the buffer containing control information to be
29 associated with the message being sent. msg_controllen specifies the
30 length of the buffer. If there’s no control information to send,
31 msg_control should be set to NULL. For detailed discussion of how to
32 set control data check nn_cmsg(3) man page.
33
34 Structure nn_iovec defines one element in the scatter array (i.e. a
35 buffer to send to the socket) and contains following members:
36
37 void *iov_base;
38 size_t iov_len;
39
40 Alternatively, to send a buffer allocated by nn_allocmsg(3) function
41 set iov_base to point to the pointer to the buffer and iov_len to
42 NN_MSG constant. In this case a successful call to nn_sendmsg will
43 deallocate the buffer. Trying to deallocate it afterwards will result
44 in undefined behaviour. Also, scatter array in nn_msghdr structure can
45 contain only one element in this case.
46
47 To which of the peers will the message be sent to is determined by the
48 particular socket type.
49
50 The flags argument is a combination of the flags defined below:
51
52 NN_DONTWAIT
53 Specifies that the operation should be performed in non-blocking
54 mode. If the message cannot be sent straight away, the function
55 will fail with errno set to EAGAIN.
56
58 If the function succeeds number of bytes in the message is returned.
59 Otherwise, -1 is returned and errno is set to to one of the values
60 defined below.
61
63 EINVAL
64 Either msghdr is NULL, there are multiple scatter buffers but
65 length is set to NN_MSG for one of them, or the sum of iov_len
66 values for the scatter buffers overflows size_t. These are early
67 checks and no pre-allocated message is freed in this case.
68
69 EMSGSIZE
70 msghdr→msg_iovlen is negative. This is an early check and no
71 pre-allocated message is freed in this case.
72
73 EFAULT
74 The supplied pointer for the pre-allocated message buffer or the
75 scatter buffer is NULL, or the length for the scatter buffer is 0.
76
77 EBADF
78 The provided socket is invalid.
79
80 ENOTSUP
81 The operation is not supported by this socket type.
82
83 EFSM
84 The operation cannot be performed on this socket at the moment
85 because socket is not in the appropriate state. This error may
86 occur with socket types that switch between several states.
87
88 EAGAIN
89 Non-blocking mode was requested and the message cannot be sent at
90 the moment.
91
92 EINTR
93 The operation was interrupted by delivery of a signal before the
94 message was sent.
95
96 ETIMEDOUT
97 Individual socket types may define their own specific timeouts. If
98 such timeout is hit this error will be returned.
99
100 ETERM
101 The library is terminating.
102
104 Usage of multiple scatter buffers:
105
106 struct nn_msghdr hdr;
107 struct nn_iovec iov [2];
108
109 iov [0].iov_base = "Hello";
110 iov [0].iov_len = 5;
111 iov [1].iov_base = "World";
112 iov [1].iov_len = 5;
113 memset (&hdr, 0, sizeof (hdr));
114 hdr.msg_iov = iov;
115 hdr.msg_iovlen = 2;
116 nn_sendmsg (s, &hdr, 0);
117
118 Usage of a single message:
119
120 void *msg;
121 struct nn_msghdr hdr;
122 struct nn_iovec iov;
123
124 msg = nn_allocmsg(12, 0);
125 strcpy(msg, "Hello World");
126 iov.iov_base = &msg;
127 iov.iov_len = NN_MSG;
128 memset (&hdr, 0, sizeof (hdr));
129 hdr.msg_iov = &iov;
130 hdr.msg_iovlen = 1;
131 nn_sendmsg (s, &hdr, 0);
132
134 nn_send(3) nn_recvmsg(3) nn_allocmsg(3) nn_freemsg(3) nn_cmsg(3)
135 nanomsg(7)
136
138 Martin Sustrik <sustrik@250bpm.com>
139
140
141
142 2018-10-15 NN_SENDMSG(3)