509 lines
12 KiB
HTML
509 lines
12 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
||
|
<title>recv()--Receive Data</title>
|
||
|
<!-- Begin Header Records ========================================== -->
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<!-- Unix8 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
||
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
||
|
<!--End Header Records -->
|
||
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<a name="Top_Of_Page"></a>
|
||
|
<!-- Java sync-link -->
|
||
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
||
|
</script>
|
||
|
|
||
|
<h2>recv()--Receive Data</h2>
|
||
|
|
||
|
<div class="box" style="width: 60%;">
|
||
|
<br>
|
||
|
BSD 4.3 Syntax<br>
|
||
|
<pre>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/socket.h>
|
||
|
|
||
|
int recv(int <em>socket_descriptor</em>,
|
||
|
char *<em>buffer</em>,
|
||
|
int <em>buffer_length</em>,
|
||
|
int <em>flags</em>)
|
||
|
</pre>
|
||
|
|
||
|
<br>
|
||
|
Service Program Name: QSOSRV1<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<div class="box" style="width: 60%;">
|
||
|
<br>
|
||
|
<a href="_xopen_source.htm">UNIX 98 Compatible Syntax</a><br>
|
||
|
<pre>
|
||
|
#define _XOPEN_SOURCE 520
|
||
|
#include <sys/socket.h>
|
||
|
|
||
|
ssize_t recv(int <em>socket_descriptor</em>,
|
||
|
void *<em>buffer</em>,
|
||
|
size_t <em>buffer_length</em>,
|
||
|
int <em>flags</em>)
|
||
|
</pre>
|
||
|
|
||
|
<br>
|
||
|
Service Program Name: QSOSRV1<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<p>The <em>recv()</em> function is used to receive data through a socket.</p>
|
||
|
|
||
|
<p> There are two versions of
|
||
|
the API, as shown above. The base i5/OS API uses BSD 4.3 structures and
|
||
|
syntax. The other uses syntax and structures compatible with the UNIX 98
|
||
|
programming interface specifications. You can select the UNIX 98 compatible
|
||
|
interface with the <a href="_xopen_source.htm">_XOPEN_SOURCE</a> macro.</p>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<h3>Parameters</h3>
|
||
|
|
||
|
<dl>
|
||
|
<dt><strong>socket_descriptor</strong></dt>
|
||
|
|
||
|
<dd>(Input) The socket descriptor that is to be read from.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>buffer</strong></dt>
|
||
|
|
||
|
<dd>(Input) The pointer to the buffer in which the data that is to be read is
|
||
|
stored.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>buffer_length</strong></dt>
|
||
|
|
||
|
<dd>(Input) The length of the <em>buffer</em>.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>flags</strong></dt>
|
||
|
|
||
|
<dd>(Input) A flag value that controls the reception of the data. The
|
||
|
<em>flags</em> value is either zero, or is obtained by performing an OR
|
||
|
operation on one or more of the following constants:
|
||
|
|
||
|
<table cellpadding="5">
|
||
|
<!-- cols="15 85" -->
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>MSG_OOB</samp></em></td>
|
||
|
<td align="left" valign="top">Receive out-of-band data. Valid only for sockets
|
||
|
with an address family of <samp>AF_INET</samp> or <samp>AF_INET6</samp> and type <samp>SOCK_STREAM</samp>.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>MSG_PEEK</samp></em></td>
|
||
|
<td align="left" valign="top">Obtain a copy of the message without removing the
|
||
|
message from the socket.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>MSG_WAITALL</samp></em></td>
|
||
|
<td align="left" valign="top">Wait for a full request or an error.</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
<h3>Authorities</h3>
|
||
|
|
||
|
<p>No authorization is required.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Return Value</h3>
|
||
|
|
||
|
<p><em>recv()</em> returns an integer. Possible values are:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>-1 (unsuccessful)<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>n (successful), where n is the number of bytes received.</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
<h3>Error Conditions</h3>
|
||
|
|
||
|
<p>When <em>recv()</em> fails, <em>errno</em> can be set to one of the
|
||
|
following:</p>
|
||
|
|
||
|
<table cellpadding="5">
|
||
|
<!-- cols="20 80" -->
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EACCES]</em></td>
|
||
|
<td align="left" valign="top">Permission denied.
|
||
|
|
||
|
<p>The socket pointed to by the <em>socket_descriptor</em> parameter is using a
|
||
|
connection-oriented transport service, and a <em>connect()</em> was previously
|
||
|
completed. The process, however, does not have the appropriate privileges to
|
||
|
the objects that were needed to establish a connection. For example, the
|
||
|
<em>connect()</em> required the use of an APPC device that the process was not
|
||
|
authorized to.</p>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EBADF]</em></td>
|
||
|
<td align="left" valign="top">Descriptor not valid.<br>
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[ECONNABORTED]</em></td>
|
||
|
<td align="left" valign="top">Connection ended abnormally.
|
||
|
|
||
|
<p>This error code indicates that the transport provider ended the connection
|
||
|
abnormally because of one of the following:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>The retransmission limit has been reached for data that was being sent on
|
||
|
the socket.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>A protocol error was detected.<br>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[ECONNREFUSED]</em></td>
|
||
|
<td align="left" valign="top">The destination socket refused an attempted
|
||
|
connect operation.<br>
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[ECONNRESET]</em></td>
|
||
|
<td align="left" valign="top">A connection with a remote socket was reset by
|
||
|
that socket.<br>
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EFAULT]</em></td>
|
||
|
<td align="left" valign="top">Bad address.
|
||
|
|
||
|
<p>The system detected an address which was not valid while attempting to
|
||
|
access the <em>buffer</em> parameter.</p>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EINTR]</em></td>
|
||
|
<td align="left" valign="top">Interrupted function call.<br>
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EINVAL]</em></td>
|
||
|
<td align="left" valign="top">Parameter not valid.
|
||
|
|
||
|
<p>This error code indicates one of the following:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>The <em>buffer_length</em> parameter specifies a negative value.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The <em>flags</em> parameter specifies a value that includes the
|
||
|
<samp>MSG_OOB</samp> flag, but no OOB data was available to be received.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The <em>flags</em> parameter specifies a value that includes the
|
||
|
<samp>MSG_OOB</samp> flag, and the socket option <samp>SO_OOBINLINE</samp> has
|
||
|
been set.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The <em>socket_descriptor</em> parameter points to a socket that is using a
|
||
|
connectionless transport service, is not a socket of type
|
||
|
<samp>SOCK_RAW</samp>, and is not bound to an address.<br>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EIO]</em></td>
|
||
|
<td align="left" valign="top">Input/output error.<br>
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[ENOBUFS]</em></td>
|
||
|
<td align="left" valign="top">There is not enough buffer space for the
|
||
|
requested operation.<br>
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[ENOTCONN]</em></td>
|
||
|
<td align="left" valign="top">Requested operation requires a connection.
|
||
|
|
||
|
<p>This error code is returned only on sockets that use a connection-oriented
|
||
|
transport service.</p>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[ENOTSOCK]</em></td>
|
||
|
<td align="left" valign="top">The specified descriptor does not reference a
|
||
|
socket.<br>
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EOPNOTSUPP]</em></td>
|
||
|
<td align="left" valign="top">Operation not supported.
|
||
|
|
||
|
<p>This error code indicates one of the following:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>The <em>flags</em> parameter specifies a value that includes the
|
||
|
<samp>MSG_OOB</samp> flag, but the <em>socket_descriptor</em> parameter points
|
||
|
to a connectionless socket.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The <em>flags</em> parameter specifies a value that includes the
|
||
|
<samp>MSG_OOB</samp> flag, but the <em>socket_descriptor</em> parameter points
|
||
|
to a socket that does not have an address family of <samp>AF_INET</samp> or <samp>AF_INET6</samp>.<br>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[ETIMEDOUT]</em></td>
|
||
|
<td align="left" valign="top">A remote host did not respond within the timeout
|
||
|
period.
|
||
|
|
||
|
<p>A nonblocking <em>connect()</em> call was previously done that resulted in
|
||
|
the connection establishment timing out. No connection is established. This
|
||
|
error code is returned only on sockets that use a connection-oriented transport
|
||
|
service.</p>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EUNATCH]</em></td>
|
||
|
<td align="left" valign="top">The protocol required to support the specified
|
||
|
address family is not available at this time.<br>
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EUNKNOWN]</em></td>
|
||
|
<td align="left" valign="top">Unknown system state.<br>
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EWOULDBLOCK]</em></td>
|
||
|
<td align="left" valign="top">Operation would have caused the thread to be
|
||
|
suspended.</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
<h3>Error Messages</h3>
|
||
|
|
||
|
<table width="100%" cellpadding="5">
|
||
|
<!-- cols="15 85" -->
|
||
|
<tr>
|
||
|
<th align="left" valign="top">Message ID</th>
|
||
|
<th align="left" valign="top">Error Message Text</th>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top">CPE3418 E</td>
|
||
|
<td align="left" valign="top">Possible APAR condition or hardware failure.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top">CPF9872 E</td>
|
||
|
<td align="left" valign="top">Program or service program &1 in library
|
||
|
&2 ended. Reason code &3.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top">CPFA081 E</td>
|
||
|
<td align="left" valign="top">Unable to set return value or error code.</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<h3>Usage Notes</h3>
|
||
|
|
||
|
<ol>
|
||
|
<li>For sockets that use a connection-oriented transport service (for example,
|
||
|
sockets with a type of <samp>SOCK_STREAM</samp>), a returned value of zero
|
||
|
indicates one of the following:
|
||
|
|
||
|
<ul>
|
||
|
<li>The partner program has issued a <em>close()</em> for the socket.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The partner program has issued a <em>shutdown()</em> to disable writing to
|
||
|
the socket.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The connection is broken and the error was returned on a previously issued
|
||
|
socket function.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>A <em>shutdown()</em> to disable reading was previously done on the
|
||
|
socket.</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The following applies to sockets that use a connectionless transport
|
||
|
service (for example, a socket with a type of <samp>SOCK_DGRAM</samp>):
|
||
|
|
||
|
<ul>
|
||
|
<li>If a <em>connect()</em> has been issued previously, then data can be
|
||
|
received only from the address specified in the previous
|
||
|
<em>connect()</em>.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The address from which data is received is discarded, since the
|
||
|
<em>recv()</em> has no address parameter.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The entire message must be read in a single read operation. If the size of
|
||
|
the message is too large to fit in the user supplied buffer, the remaining
|
||
|
bytes of the message are discarded.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>A returned value of zero indicates one of the following:
|
||
|
|
||
|
<ul>
|
||
|
<li>The partner program has sent a NULL message (a datagram with no user
|
||
|
data),<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>A <em>shutdown()</em> to disable reading was previously done on the
|
||
|
socket.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The buffer length specified was zero.</li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
</ul><br>
|
||
|
</li>
|
||
|
|
||
|
<li>When you develop in C-based
|
||
|
languages and an application is compiled with the _XOPEN_SOURCE macro defined
|
||
|
to the value 520 or greater, the <em>recv()</em> API is mapped to
|
||
|
<em>qso_recv98()</em>.</li>
|
||
|
</ol>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<h3>Related Information</h3>
|
||
|
|
||
|
<ul>
|
||
|
<li><a href=
|
||
|
"_xopen_source.htm">_XOPEN_SOURCE</a>--Using _XOPEN_SOURCE for the UNIX 98
|
||
|
compatible interface<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="fcntl.htm">fcntl()</a>--Perform File Control Command<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="ioctl.htm">ioctl()</a>--Perform I/O Control Request<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="recvfr.htm">recvfrom()</a>--Receive Data<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="recvms.htm">recvmsg()</a>--Receive Data or Descriptors or
|
||
|
Both</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
<hr>
|
||
|
API introduced: V3R1
|
||
|
|
||
|
<hr>
|
||
|
<center>
|
||
|
<table cellpadding="2" cellspacing="2">
|
||
|
<tr align="center">
|
||
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> |
|
||
|
<a href="unix.htm">UNIX-Type APIs</a> |
|
||
|
<a href="aplist.htm">APIs by category</a> </td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</center>
|
||
|
</body>
|
||
|
</html>
|
||
|
|