'\" t .\" Title: xs_recvmsg .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.75.2 .\" Date: 06/13/2012 .\" Manual: Crossroads I/O Manual .\" Source: Crossroads I/O 1.2.0 .\" Language: English .\" .TH "XS_RECVMSG" "3" "06/13/2012" "Crossroads I/O 1\&.2\&.0" "Crossroads I/O Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" xs_recvmsg \- receive a message part from a socket (zero\-copy) .SH "SYNOPSIS" .sp \fBint xs_recvmsg (void \fR\fB\fI*socket\fR\fR\fB, xs_msg_t \fR\fB\fI*msg\fR\fR\fB, int \fR\fB\fIflags\fR\fR\fB);\fR .SH "DESCRIPTION" .sp The \fIxs_recvmsg()\fR function shall receive a message part from the socket referenced by the \fIsocket\fR argument and store it in the message referenced by the \fImsg\fR argument\&. Any content previously stored in \fImsg\fR shall be properly deallocated\&. If there are no message parts available on the specified \fIsocket\fR the \fIxs_recvmsg()\fR function shall block until the request can be satisfied\&. The \fIflags\fR argument is a combination of the flags defined below: .PP \fBXS_DONTWAIT\fR .RS 4 Specifies that the operation should be performed in non\-blocking mode\&. If there are no messages available on the specified \fIsocket\fR, the \fIxs_recvmsg()\fR function shall fail with \fIerrno\fR set to EAGAIN\&. .RE .SS "Multi\-part messages" .sp A Crossroads message is composed of 1 or more message parts\&. Each message part is an independent \fIxs_msg_t\fR in its own right\&. Crossroads ensures atomic delivery of messages; peers shall receive either all \fImessage parts\fR of a message or none at all\&. The total number of message parts is unlimited except by available memory\&. .sp An application that processes multipart messages must use the \fIXS_RCVMORE\fR \fBxs_getsockopt\fR(3) option after calling \fIxs_recvmsg()\fR to determine if there are further parts to receive\&. .SH "RETURN VALUE" .sp The \fIxs_recvmsg()\fR function shall return the number of bytes in the received message if successful\&. Otherwise it shall return \-1 and set \fIerrno\fR to one of the values defined below\&. .SH "ERRORS" .PP \fBEAGAIN\fR .RS 4 Non\-blocking mode was requested and no messages are available at the moment\&. .RE .PP \fBENOTSUP\fR .RS 4 The \fIxs_recvmsg()\fR operation is not supported by this socket type\&. .RE .PP \fBEFSM\fR .RS 4 The \fIxs_recvmsg()\fR operation cannot be performed on this socket at the moment due to the socket not being in the appropriate state\&. This error may occur with socket types that switch between several states, such as XS_REP\&. See the \fImessaging patterns\fR section of \fBxs_socket\fR(3) for more information\&. .RE .PP \fBETERM\fR .RS 4 The \fIcontext\fR associated with the specified \fIsocket\fR was terminated\&. .RE .PP \fBENOTSOCK\fR .RS 4 The provided \fIsocket\fR was invalid\&. .RE .PP \fBEINTR\fR .RS 4 The operation was interrupted by delivery of a signal before a message was available\&. .RE .PP \fBEFAULT\fR .RS 4 The message passed to the function was invalid\&. .RE .PP \fBETIMEDOUT\fR .RS 4 Survey has timed out\&. (Applicable only to XS_SURVEYOR socket\&.) .RE .SH "EXAMPLE" .PP \fBReceiving a message from a socket\fR. .sp .if n \{\ .RS 4 .\} .nf /* Create an empty message */ xs_msg_t msg; int rc = xs_msg_init (&msg); assert (rc == 0); /* Block until a message is available to be received from socket */ rc = xs_recvmsg (socket, &msg, 0); assert (rc != \-1); /* Release message */ xs_msg_close (&msg); .fi .if n \{\ .RE .\} .PP \fBReceiving a multi-part message\fR. .sp .if n \{\ .RS 4 .\} .nf int64_t more; size_t more_size = sizeof more; do { /* Create an empty message to hold the message part */ xs_msg_t part; int rc = xs_msg_init (&part); assert (rc == 0); /* Block until a message is available to be received from socket */ rc = xs_recvmsg (socket, &part, 0); assert (rc != \-1); /* Determine if more message parts are to follow */ rc = xs_getsockopt (socket, XS_RCVMORE, &more, &more_size); assert (rc == 0); xs_msg_close (&part); } while (more); .fi .if n \{\ .RE .\} .sp .SH "SEE ALSO" .sp Applications that do not require zero\-copy messaging can use the simpler \fBxs_recv\fR(3) instead of \fIxs_recvmsg()\fR\&. .sp \fBxs_sendmsg\fR(3) \fBxs_getsockopt\fR(3) \fBxs_socket\fR(7) \fBxs\fR(7) .SH "AUTHORS" .sp This man page was written by Martin Sustrik <\m[blue]\fBsustrik@250bpm\&.com\fR\m[]\&\s-2\u[1]\d\s+2>, Martin Lucina <\m[blue]\fBmartin@lucina\&.net\fR\m[]\&\s-2\u[2]\d\s+2> and Pieter Hintjens <\m[blue]\fBph@imatix\&.com\fR\m[]\&\s-2\u[3]\d\s+2>\&. .SH "NOTES" .IP " 1." 4 sustrik@250bpm.com .RS 4 \%mailto:sustrik@250bpm.com .RE .IP " 2." 4 martin@lucina.net .RS 4 \%mailto:martin@lucina.net .RE .IP " 3." 4 ph@imatix.com .RS 4 \%mailto:ph@imatix.com .RE