TCP/IP Programming Manual
Errors
If an error occurs, the return value is set to -1 and the external variable errno is set to one of the
following values:
There is out-of-band data pending. This must be cleared with a call to recv with the
MSG_OOB flag set. (This error does not apply to UDP sockets.)
EHAVEOOB
The specified socket was not connected.ENOTCONN
The specified socket was shut down.ESHUTDOWN
The connection timed out.ETIMEDOUT
The connection was reset by the remote host.ECONNRESET
Usage Guidelines
Use the following guidelines for the recv and recv_nw functions:
• Use recv on a socket created for waited operations. Use recv_nw on a socket created with
the socket_nw call for nowait operations. The operation initiated by recv_nw must be
completed with a call to the AWAITIOX procedure.
• To determine the number of characters read from recv_nw, check the third parameter (the
count transferred) returned by the AWAITIOX procedure. Refer to the Guardian Procedure
Calls Reference Manual for details about the AWAITIOX procedure and its parameters.
• recv and recvfrom could wait indefinitely if the network terminates the connection
ungracefully, without returning an error code. This is standard TCP/IP behavior. Avoid the
wait by calling recv_nw or recvfrom_nw nowait operations, followed by calling AWAITIOX
with a timer value of 10 seconds. If the timer expires, call send or sendto from the local
host. If the send or sendto call fails, the connection is down.
• The sending side of a connection indicates end-of-file by closing or shutting down its socket.
The receiving side recognizes end-of-file when the recv or recvfrom calls have 0 bytes in
their length-of-buffer field. This is standard practice, not specific to the Guardian socket
library implementation. You are responsible for handling this condition.
• If the MSG_OOB flag is set by itself, only the last byte of urgent data sent from the remote site
is received. To receive multiple bytes of urgent data in the normal data stream, you must set
the socket option SO_OOBINLINE, and call recv with the MSG_OOB flag set. recv returns
data through the last byte of urgent data. The SO_OOBINLINE socket option is set with either
the setsockopt or setsockopt_nw functions. To determine where the last byte of urgent
data occurs, use the socket_ioctl() operation SIOCATMARK.
See Nowait Call Errors (page 86) for information on checking errors.
Example
The following programming example calls the recv function. (In the example, rsock is a socket
created by a previous call to socket):
#include <socket.h>
#include <netdb.h>
...
int status, tosend;
char buffer [8*1024];
...
tosend = sizeof(buffer);
status = recv(rsock, (char *)&buffer[0], tosend, 0);
recv64_, recv_nw64_
The recv64_ and recv_nw64_ functions receive data on a connected socket.
recv64_, recv_nw64_ 155