'\" t
.\"     Title: nn_sendmsg
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.18
.\"      Date: 2021-02-08
.\"    Manual: NNG Reference Manual
.\"    Source: \ \&
.\"  Language: English
.\"
.TH "NN_SENDMSG" "3compat" "2021-02-08" "\ \&" "NNG Reference Manual"
.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 \- send message (compatible API)
.SH "SYNOPSIS"
.sp
.if n .RS 4
.nf
.fam C
#include <nanomsg/nn.h>

int nn_sendmsg(int sock, const struct nn_msghdr *hdr, int flags);
.fam
.fi
.if n .RE
.SH "DESCRIPTION"
.sp
The \f(CRnn_sendmsg()\fP function sends the message described by \fIhdr\fP using the
socket \fIsock\fP.
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Note
.ps -1
.br
.sp
This function is provided for API
compatibility with legacy \fIlibnanomsg\fP.
Consider using the relevant modern API instead.
.sp .5v
.RE
.sp
The \fIflags\fP field may contain the special flag \f(CRNN_DONTWAIT\fP.
In this case, if the socket is unable to accept more data for sending,
the operation shall not block, but instead will fail with the error \f(CREAGAIN\fP.
.sp
The \fIhdr\fP points to a structure of type \f(CRstruct nn_msghdr\fP, which has the
following definition:
.sp
.if n .RS 4
.nf
.fam C
struct nn_iovec {
    void * iov_base;
    size_t iov_len;
};

struct nn_msghdr {
    struct nn_iovec *msg_iov;
    int              msg_iovlen;
    void *           msg_control;
    size_t           msg_controllen;
};
.fam
.fi
.if n .RE
.sp
The \f(CRmsg_iov\fP is an array of gather items, permitting the message
to be spread into different memory blocks.
There are \f(CRmsg_iovlen\fP elements in this array, each of which
has the base address (\f(CRiov_base\fP) and length (\f(CRiov_len\fP) indicated.
.sp
For buffers allocated for zero copy
(such as by \f(CRnn_allocmsg()\fP), the value
of \f(CRiov_base\fP should be the address of the pointer to the buffer,
rather than the address of the buffer itself.
In this case, the value of \f(CRiov_len\fP should be \f(CRNN_MSG\fP,
as the length is inferred from the allocated message.
If the \f(CRmsg_iovlen\fP field is \f(CRNN_MSG\fP, then this function will free
the associated buffer after it is done with it, if it returns successfully.
(If the function returns with an error, then the caller retains ownership
of the associated buffer and may retry the operation or free the buffer
at its choice.)
.sp
The values of \f(CRmsg_control\fP and \f(CRmsg_controllen\fP describe a buffer
of ancillary data to send the message.
This is currently only useful to provide the message headers
used with raw mode sockets.
In all other circumstances these fields should be zero.
Details about this structure are covered in
\f(CRnn_cmsg(3compat)\fP.
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Note
.ps -1
.br
.sp
The send operation is performed asynchronously, and may not have
completed before this function returns control to the caller.
.sp .5v
.RE
.SH "RETURN VALUES"
.sp
This function returns the number of bytes sent on success, and \-1 on error.
.SH "ERRORS"
.sp
\f(CREAGAIN\fP
.RS 4
The operation would block.
.RE
.sp
\f(CREBADF\fP
.RS 4
The socket \fIsock\fP is not open.
.RE
.sp
\f(CREFSM\fP
.RS 4
The socket cannot send in this state.
.RE
.sp
\f(CREINVAL\fP
.RS 4
The \fIhdr\fP is invalid.
.RE
.sp
\f(CRENOTSUP\fP
.RS 4
This protocol cannot send.
.RE
.sp
\f(CRETIMEDOUT\fP
.RS 4
Operation timed out.
.RE
.SH "SEE ALSO"
.sp
nn_cmsg(3compat),
nn_errno(3compat),
nn_recv(3compat),
nn_send(3compat),
nn_socket(3compat),
nn_compat(3compat),
nng(7)