Sends data specified by msghdr parameter to socket s along with any additional control data. msghdr structure should be nullified before being used.
Structure nn_msghdr contains at least following members:
struct nn_iovec *msg_iov; int msg_iovlen; void *msg_control; size_t msg_controllen;
msg_iov points to a scatter array of buffers to send. msg_iovlen specifies the size of the array.
msg_control points to the buffer containing control information to be associated with the message being sent. msg_controllen specifies the length of the buffer. If there's no control information to send, msg_control should be set to NULL. For detailed discussion of how to set control data check nn_cmsg(3) man page.
Structure nn_iovec defines one element in the scatter array (i.e. a buffer to send to the socket) and contains following members:
void *iov_base; size_t iov_len;
Alternatively, to send a buffer allocated by nn_allocmsg(3) function set iov_base to point to the pointer to the buffer and iov_len to NN_MSG constant. In this case a successful call to nn_sendmsg will deallocate the buffer. Trying to deallocate it afterwards will result in undefined behaviour. Also, scatter array in nn_msghdr structure can contain only one element in this case.
To which of the peers will the message be sent to is determined by the particular socket type.
The flags argument is a combination of the flags defined below:
Usage of multiple scatter buffers:
struct nn_msghdr hdr; struct nn_iovec iov ; iov .iov_base = "Hello"; iov .iov_len = 5; iov .iov_base = "World"; iov .iov_len = 5; memset (&hdr, 0, sizeof (hdr)); hdr.msg_iov = iov; hdr.msg_iovlen = 2; nn_sendmsg (s, &hdr, 0);
Usage of a single message:
void *msg; struct nn_msghdr hdr; struct nn_iovec iov; msg = nn_allocmsg(12, 0); strcpy(msg, "Hello World"); iov.iov_base = &msg; iov.iov_len = NN_MSG; memset (&hdr, 0, sizeof (hdr)); hdr.msg_iov = &iov; hdr.msg_iovlen = 1; nn_sendmsg (s, &hdr, 0);