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

int nn_recvmsg(int sock, struct nn_msghdr *hdr, int flags);
.fam
.fi
.if n .RE
.SH "DESCRIPTION"
.sp
The \f(CRnn_recvmsg()\fP function receives a message into the header 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 no message is ready for receiving on \fIsock\fP,
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 scatter 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
The last member of this array may have the \f(CRiov_len\fP field set to \f(CRNN_MSG\fP,
in which case the function shall allocate a message buffer, and store the
pointer to it at the address indicated by \f(CRiov_base\fP.
This can help save an extra copy operation.
The buffer should be deallocated by \f(CRnn_freemsg()\fP
or similar when it is no longer needed.
.sp
The values of \f(CRmsg_control\fP and \f(CRmsg_controllen\fP describe a buffer
of ancillary data associated with the message.
This is currently only useful to obtain 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.
.SH "RETURN VALUES"
.sp
This function returns the number of bytes received 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 receive 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 receive.
.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)