227 lines
7.9 KiB
HTML
227 lines
7.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>recv</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
|
|
<basefont size="3"> <a name="recv"></a> <a name="tag_03_600"></a><!-- recv -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_600_01"></a>NAME</h4>
|
|
|
|
<blockquote>recv - receive a message from a connected socket</blockquote>
|
|
|
|
<h4><a name="tag_03_600_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/sys/socket.h.html">sys/socket.h</a>><br>
|
|
<br>
|
|
ssize_t recv(int</tt> <i>socket</i><tt>, void *</tt><i>buffer</i><tt>, size_t</tt> <i>length</i><tt>, int</tt>
|
|
<i>flags</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_600_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>recv</i>() function shall receive a message from a connection-mode or connectionless-mode socket. It is normally used
|
|
with connected sockets because it does not permit the application to retrieve the source address of received data.</p>
|
|
|
|
<p>The <i>recv</i>() function takes the following arguments:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>socket</i></dt>
|
|
|
|
<dd>Specifies the socket file descriptor.</dd>
|
|
|
|
<dt><i>buffer</i></dt>
|
|
|
|
<dd>Points to a buffer where the message should be stored.</dd>
|
|
|
|
<dt><i>length</i></dt>
|
|
|
|
<dd>Specifies the length in bytes of the buffer pointed to by the <i>buffer</i> argument.</dd>
|
|
|
|
<dt><i>flags</i></dt>
|
|
|
|
<dd>Specifies the type of message reception. Values of this argument are formed by logically OR'ing zero or more of the following
|
|
values:
|
|
|
|
<dl compact>
|
|
<dt>MSG_PEEK</dt>
|
|
|
|
<dd>Peeks at an incoming message. The data is treated as unread and the next <i>recv</i>() or similar function shall still return
|
|
this data.</dd>
|
|
|
|
<dt>MSG_OOB</dt>
|
|
|
|
<dd>Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific.</dd>
|
|
|
|
<dt>MSG_WAITALL</dt>
|
|
|
|
<dd>On SOCK_STREAM sockets this requests that the function block until the full amount of data can be returned. The function may
|
|
return the smaller amount of data if the socket is a message-based socket, if a signal is caught, if the connection is terminated,
|
|
if MSG_PEEK was specified, or if an error is pending for the socket.</dd>
|
|
</dl>
|
|
</dd>
|
|
</dl>
|
|
|
|
<p>The <i>recv</i>() function shall return the length of the message written to the buffer pointed to by the <i>buffer</i>
|
|
argument. For message-based sockets, such as SOCK_DGRAM and SOCK_SEQPACKET, the entire message shall be read in a single operation.
|
|
If a message is too long to fit in the supplied buffer, and MSG_PEEK is not set in the <i>flags</i> argument, the excess bytes
|
|
shall be discarded. For stream-based sockets, such as SOCK_STREAM, message boundaries shall be ignored. In this case, data shall be
|
|
returned to the user as soon as it becomes available, and no data shall be discarded.</p>
|
|
|
|
<p>If the MSG_WAITALL flag is not set, data shall be returned only up to the end of the first message.</p>
|
|
|
|
<p>If no messages are available at the socket and O_NONBLOCK is not set on the socket's file descriptor, <i>recv</i>() shall block
|
|
until a message arrives. If no messages are available at the socket and O_NONBLOCK is set on the socket's file descriptor,
|
|
<i>recv</i>() shall fail and set <i>errno</i> to [EAGAIN] or [EWOULDBLOCK].</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_600_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, <i>recv</i>() shall return the length of the message in bytes. If no messages are available to be
|
|
received and the peer has performed an orderly shutdown, <i>recv</i>() shall return 0. Otherwise, -1 shall be returned and
|
|
<i>errno</i> set to indicate the error.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_600_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>recv</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EAGAIN] or [EWOULDBLOCK]</dt>
|
|
|
|
<dd><br>
|
|
The socket's file descriptor is marked O_NONBLOCK and no data is waiting to be received; or MSG_OOB is set and no out-of-band data
|
|
is available and either the socket's file descriptor is marked O_NONBLOCK or the socket does not support blocking to await
|
|
out-of-band data.</dd>
|
|
|
|
<dt>[EBADF]</dt>
|
|
|
|
<dd>The <i>socket</i> argument is not a valid file descriptor.</dd>
|
|
|
|
<dt>[ECONNRESET]</dt>
|
|
|
|
<dd>A connection was forcibly closed by a peer.</dd>
|
|
|
|
<dt>[EINTR]</dt>
|
|
|
|
<dd>The <i>recv</i>() function was interrupted by a signal that was caught, before any data was available.</dd>
|
|
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The MSG_OOB flag is set and no out-of-band data is available.</dd>
|
|
|
|
<dt>[ENOTCONN]</dt>
|
|
|
|
<dd>A receive is attempted on a connection-mode socket that is not connected.</dd>
|
|
|
|
<dt>[ENOTSOCK]</dt>
|
|
|
|
<dd>The <i>socket</i> argument does not refer to a socket.</dd>
|
|
|
|
<dt>[EOPNOTSUPP]</dt>
|
|
|
|
<dd>The specified flags are not supported for this socket type or protocol.</dd>
|
|
|
|
<dt>[ETIMEDOUT]</dt>
|
|
|
|
<dd>The connection timed out during connection establishment, or due to a transmission timeout on active connection.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>recv</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EIO]</dt>
|
|
|
|
<dd>An I/O error occurred while reading from or writing to the file system.</dd>
|
|
|
|
<dt>[ENOBUFS]</dt>
|
|
|
|
<dd>Insufficient resources were available in the system to perform the operation.</dd>
|
|
|
|
<dt>[ENOMEM]</dt>
|
|
|
|
<dd>Insufficient memory was available to fulfill the request.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_600_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_600_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>recv</i>() function is equivalent to <a href="../functions/recvfrom.html"><i>recvfrom</i>()</a> with a zero
|
|
<i>address_len</i> argument, and to <a href="../functions/read.html"><i>read</i>()</a> if no flags are used.</p>
|
|
|
|
<p>The <a href="../functions/select.html"><i>select</i>()</a> and <a href="../functions/poll.html"><i>poll</i>()</a> functions can
|
|
be used to determine when data is available to be received.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_600_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_600_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_600_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="poll.html"><i>poll</i>()</a> , <a href="read.html"><i>read</i>()</a> , <a href="recvmsg.html"><i>recvmsg</i>()</a> , <a
|
|
href="recvfrom.html"><i>recvfrom</i>()</a> , <a href="select.html"><i>select</i>()</a> , <a href="send.html"><i>send</i>()</a> , <a
|
|
href="sendmsg.html"><i>sendmsg</i>()</a> , <a href="sendto.html"><i>sendto</i>()</a> , <a href=
|
|
"shutdown.html"><i>shutdown</i>()</a> , <a href="socket.html"><i>socket</i>()</a> , <a href="write.html"><i>write</i>()</a> , the
|
|
Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_600_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|