'\" t .\" Title: nn_sendmsg .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.20 .\" Date: 2024-02-21 .\" Manual: nanomsg 1.2.1 .\" Source: \ \& .\" Language: English .\" .TH "NN_SENDMSG" "3" "2024-02-21" "\ \&" "nanomsg 1.2.1" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 .nh .ad l .de URL \fI\\$2\fP <\\$1>\\$3 .. .als MTO URL .if \n[.g] \{\ . mso www.tmac . am URL . ad l . . . am MTO . ad l . . . LINKSTYLE blue R < > .\} .SH "NAME" nn_sendmsg \- fine\-grained alternative to nn_send .SH "SYNOPSIS" .sp \fB#include \fP .sp \fBint nn_sendmsg (int \fIs\fP, const struct nn_msghdr \fI*msghdr\fP, int \fIflags\fP);\fP .SH "DESCRIPTION" .sp Sends data specified by \fImsghdr\fP parameter to socket \fIs\fP along with any additional control data. \fImsghdr\fP structure should be nullified before being used. .sp Structure \fInn_msghdr\fP contains at least following members: .sp .if n .RS 4 .nf .fam C struct nn_iovec *msg_iov; int msg_iovlen; void *msg_control; size_t msg_controllen; .fam .fi .if n .RE .sp \fImsg_iov\fP points to a scatter array of buffers to send. \fImsg_iovlen\fP specifies the size of the array. .sp \fImsg_control\fP points to the buffer containing control information to be associated with the message being sent. \fImsg_controllen\fP specifies the length of the buffer. If there\(cqs no control information to send, \fImsg_control\fP should be set to NULL. For detailed discussion of how to set control data check nn_cmsg(3) man page. .sp Structure \fInn_iovec\fP defines one element in the scatter array (i.e. a buffer to send to the socket) and contains following members: .sp .if n .RS 4 .nf .fam C void *iov_base; size_t iov_len; .fam .fi .if n .RE .sp Alternatively, to send a buffer allocated by nn_allocmsg(3) function set \fIiov_base\fP to point to the pointer to the buffer and \fIiov_len\fP to \fINN_MSG\fP constant. In this case a successful call to \fInn_sendmsg\fP will deallocate the buffer. Trying to deallocate it afterwards will result in undefined behaviour. Also, scatter array in \fInn_msghdr\fP structure can contain only one element in this case. .sp To which of the peers will the message be sent to is determined by the particular socket type. .sp The \fIflags\fP argument is a combination of the flags defined below: .sp \fBNN_DONTWAIT\fP .RS 4 Specifies that the operation should be performed in non\-blocking mode. If the message cannot be sent straight away, the function will fail with \fIerrno\fP set to EAGAIN. .RE .SH "RETURN VALUE" .sp If the function succeeds number of bytes in the message is returned. Otherwise, \-1 is returned and \fIerrno\fP is set to to one of the values defined below. .SH "ERRORS" .sp \fBEINVAL\fP .RS 4 Either \fImsghdr\fP is NULL, there are multiple scatter buffers but length is set to \fINN_MSG\fP for one of them, or the sum of \fIiov_len\fP values for the scatter buffers overflows \fIsize_t\fP. These are early checks and no pre\-allocated message is freed in this case. .RE .sp \fBEMSGSIZE\fP .RS 4 msghdr\(->msg_iovlen is negative. This is an early check and no pre\-allocated message is freed in this case. .RE .sp \fBEFAULT\fP .RS 4 The supplied pointer for the pre\-allocated message buffer or the scatter buffer is NULL, or the length for the scatter buffer is 0. .RE .sp \fBEBADF\fP .RS 4 The provided socket is invalid. .RE .sp \fBENOTSUP\fP .RS 4 The operation is not supported by this socket type. .RE .sp \fBEFSM\fP .RS 4 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. .RE .sp \fBEAGAIN\fP .RS 4 Non\-blocking mode was requested and the message cannot be sent at the moment. .RE .sp \fBEINTR\fP .RS 4 The operation was interrupted by delivery of a signal before the message was sent. .RE .sp \fBETIMEDOUT\fP .RS 4 Individual socket types may define their own specific timeouts. If such timeout is hit this error will be returned. .RE .sp \fBETERM\fP .RS 4 The library is terminating. .RE .SH "EXAMPLE" .sp Usage of multiple scatter buffers: .sp .if n .RS 4 .nf .fam C struct nn_msghdr hdr; struct nn_iovec iov [2]; iov [0].iov_base = "Hello"; iov [0].iov_len = 5; iov [1].iov_base = "World"; iov [1].iov_len = 5; memset (&hdr, 0, sizeof (hdr)); hdr.msg_iov = iov; hdr.msg_iovlen = 2; nn_sendmsg (s, &hdr, 0); .fam .fi .if n .RE .sp Usage of a single message: .sp .if n .RS 4 .nf .fam C 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); .fam .fi .if n .RE .SH "SEE ALSO" .sp nn_send(3) nn_recvmsg(3) nn_allocmsg(3) nn_freemsg(3) nn_cmsg(3) nanomsg(7) .SH "AUTHORS" .sp .MTO "sustrik\(at250bpm.com" "Martin Sustrik" ""