2 .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved Portions Copyright (c) 1998, Sun Microsystems, Inc. All Rights Reserved
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
6 .\" This notice shall appear on any product containing this material.
7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
10 .TH RECV 3XNET "Dec 03, 2014"
12 recv \- receive a message from a connected socket
16 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lxnet\fR [ \fIlibrary\fR ... ]
17 #include <sys/socket.h>
19 \fBssize_t\fR \fBrecv\fR(\fBint\fR \fIsocket\fR, \fBvoid *\fR\fIbuffer\fR, \fBsize_t\fR \fIlength\fR, \fBint\fR \fIflags\fR);
24 The \fBrecv()\fR function receives a message from a connection-mode or
25 connectionless-mode socket. It is normally used with connected sockets because
26 it does not permit the application to retrieve the source address of received
27 data. The function takes the following arguments:
34 Specifies the socket file descriptor.
43 Points to a buffer where the message should be stored.
52 Specifies the length in bytes of the buffer pointed to by the \fIbuffer\fR
62 Specifies the type of message reception. Values of this argument are formed by
63 logically OR'ing zero or more of the following values:
70 Peeks at an incoming message. The data is treated as unread and the next
71 \fBrecv()\fR or similar function will still return this data.
80 Requests out-of-band data. The significance and semantics of out-of-band data
81 are protocol-specific.
90 Requests that the function block until the full amount of data requested can be
91 returned. The function may return a smaller amount of data if a signal is
92 caught, if the connection is terminated, if \fBMSG_PEEK\fR was specified, or
93 if an error is pending for the socket.
100 The \fBrecv()\fR function returns the length of the message written to the
101 buffer pointed to by the \fIbuffer\fR argument. For message-based sockets such
102 as \fBSOCK_DGRAM\fR and \fBSOCK_SEQPACKET\fR, the entire message must be read
103 in a single operation. If a message is too long to fit in the supplied buffer,
104 and \fBMSG_PEEK\fR is not set in the \fIflags\fR argument, the excess bytes are
105 discarded. For stream-based sockets such as \fBSOCK_STREAM\fR, message
106 boundaries are ignored. In this case, data is returned to the user as soon as
107 it becomes available, and no data is discarded.
110 If the \fBMSG_WAITALL\fR flag is not set, data will be returned only up to the
111 end of the first message.
114 If no messages are available at the socket and \fBO_NONBLOCK\fR is not set on
115 the socket's file descriptor, \fBrecv()\fR blocks until a message arrives. If
116 no messages are available at the socket and \fBO_NONBLOCK\fR is set on the
117 socket's file descriptor, \fBrecv()\fR fails and sets \fBerrno\fR to
118 \fBEAGAIN\fR or \fBEWOULDBLOCK\fR.
121 The \fBrecv()\fR function is identical to \fBrecvfrom\fR(3XNET) with a zero
122 \fIaddress_len\fR argument, and to \fBread()\fR if no flags are used.
125 The \fBselect\fR(3C) and \fBpoll\fR(2) functions can be used to determine when
126 data is available to be received.
129 Upon successful completion, \fBrecv()\fR returns the length of the message in
130 bytes. If no messages are available to be received and the peer has performed
131 an orderly shutdown, \fBrecv()\fR returns 0. Otherwise, -1 is returned and
132 \fBerrno\fR is set to indicate the error.
135 The \fBrecv()\fR function will fail if:
143 \fB\fBEWOULDBLOCK\fR\fR
146 The socket's file descriptor is marked \fBO_NONBLOCK\fR and no data is waiting
147 to be received; or \fBMSG_OOB\fR is set and no out-of-band data is available
148 and either the socket's file descriptor is marked \fBO_NONBLOCK\fR or the
149 socket does not support blocking to await out-of-band data.
158 The \fIsocket\fR argument is not a valid file descriptor.
164 \fB\fBECONNRESET\fR\fR
167 The \fIsocket\fR argument refers to a connection oriented socket and the
168 connection was forcibly closed by the peer and is no longer valid. I/O can no
169 longer be performed to \fIfiledes\fR.
178 The \fIbuffer\fR parameter can not be accessed or written.
187 The \fBrecv()\fR function was interrupted by a signal that was caught, before
188 any data was available.
197 The \fBMSG_OOB\fR flag is set and no out-of-band data is available.
206 A receive is attempted on a connection-mode socket that is not connected.
215 The \fIsocket\fR argument does not refer to a socket.
221 \fB\fBEOPNOTSUPP\fR\fR
224 The specified flags are not supported for this socket type or protocol.
230 \fB\fBETIMEDOUT\fR\fR
233 The connection timed out during connection establishment, or due to a
234 transmission timeout on active connection.
239 The \fBrecv()\fR function may fail if:
246 An I/O error occurred while reading from or writing to the file system.
255 Insufficient resources were available in the system to perform the operation.
264 Insufficient memory was available to fulfill the request.
273 There were insufficient STREAMS resources available for the operation to
279 See \fBattributes\fR(5) for descriptions of the following attributes:
287 ATTRIBUTE TYPE ATTRIBUTE VALUE
289 Interface Stability Standard
296 \fBpoll\fR(2), \fBrecvmsg\fR(3XNET), \fBrecvfrom\fR(3XNET), \fBselect\fR(3C),
297 \fBsend\fR(3XNET), \fBsendmsg\fR(3XNET), \fBsendto\fR(3XNET),
298 \fBshutdown\fR(3XNET), \fBsocket\fR(3XNET), \fBattributes\fR(5),