[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Communications Technical Reference, Volume 2

recv Subroutine

Purpose

Receives messages from connected sockets.

Library

Standard C Library (libc.a)

Syntax

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
int recv (Socket, 
Buffer, Length, Flags)
int Socket;
void *Buffer;
size_t Length;
int Flags;

Description

The recv subroutine receives messages from a connected socket. The recvfrom and recvmsg subroutines receive messages from both connected and unconnected sockets. However, they are usually used for unconnected sockets only.

The recv subroutine returns the length of the message. If a message is too long to fit in the supplied buffer, excess bytes may be truncated depending on the type of socket that issued the message.

If no messages are available at the socket, the recv subroutine waits for a message to arrive, unless the socket is nonblocking. If a socket is nonblocking, the system returns an error.

Use the select subroutine to determine when more data arrives.

Parameters

Socket Specifies the socket descriptor.
Buffer Specifies an address where the message should be placed.
Length Specifies the size of the Buffer parameter.
Flags Points to a value controlling the message reception. The /usr/include/sys/socket.h file defines the Flags parameter. The argument to receive a call is formed by logically ORing one or more of the following values:
MSG_PEEK Peeks at incoming message. The data is treated as unread, and the next recv subroutine still returns this data.
MSG_OOB Processes out-of-band data.

Return Values

Upon successful completion, the recv subroutine returns the length of the message in bytes.

If the recv subroutine is unsuccessful, the subroutine handler performs the following functions:

Error Codes

The recv subroutine is unsuccessful if any of the following errors occurs:

EBADF The Socket parameter is not valid.
ENOTSOCK The Socket parameter refers to a file, not a socket.
EWOULDBLOCK The socket is marked nonblocking, and no connections are present to be accepted.
EINTR A signal interrupted the recv subroutine before any data was available.
EFAULT The data was directed to be received into a nonexistent or protected part of the process address space. The Buffer parameter is not valid.

Implementation Specifics

The recv subroutine is part of Base Operating System (BOS) Runtime.

The socket applications can be compiled with COMPAT_43 defined. This will make the sockaddr structure BSD 4.3 compatible. For more details refer to socket.h.

Related Information

The fgets subroutine, fputs subroutine, read subroutine, recvfrom subroutine, recvmsg subroutine, select subroutine, send subroutine, sendmsg subroutine, sendto subroutine, shutdown subroutine, socket subroutine, write subroutine.

Sockets Overview and Understanding Socket Data Transfer in AIX Version 4.3 Communications Programming Concepts.


[ Previous | Next | Contents | Glossary | Home | Search ]