Open System Services System Calls Reference Manual (G06.25+, H06.03+)
System Functions (r) recv(2)
NAME
recv - Receives a message from a connected socket
LIBRARY
G-series native OSS processes: system library
H-series OSS processes: implicit libraries
SYNOPSIS
#include <sys/socket.h>
ssize_t recv(
int socket,
void *buffer,
size_t length,
int flags
);
PARAMETERS
socket Specifies the file descriptor of the socket.
buffer Points to the buffer where the message should be written.
length Specifies the length in bytes of the buffer pointed to by the buffer parameter.
flags Is a value that controls message reception. The value of the flags parameter is
formed by bitwise ORing zero or more of the following values:
MSG_OOB Requests out-of-band data.
MSG_PEEK Peeks at an incoming message. The data is treated as unread and
the next call to the recv() function (or similar function) will still
return this data.
DESCRIPTION
The recv() function receives messages from a connected socket.
For message-based sockets (sockets of type SOCK_DGRAM), the entire message must be read
in one call. If a message is too long to fit in the supplied buffer and MSG_PEEK is not set in the
flags parameter, the excess bytes are discarded.
For stream-based sockets (sockets of type SOCK_STREAM), message boundaries are ignored.
For such sockets, data is returned as soon as it becomes available; no data is discarded.
If no messages are available at the socket and the socket’s file descriptor is blocking
(O_NONBLOCK is not set), the recv() function blocks until a message arrives. If no messages
are available at the socket and the socket’s file descriptor is marked nonblocking
(O_NONBLOCK is set), the recv() function fails and sets errno to [EWOULDBLOCK].
NOTES
When data is available, a call to the select() function indicates that the file descriptor for the
socket is ready for reading.
Calling the recv() function with a flags parameter of 0 (zero) is identical to calling the read()
function.
RETURN VALUES
Upon successful completion, the recv() function returns the length of the received message in
bytes. If no data is available and the peer socket has performed an orderly shutdown, then 0
(zero) is returned.
527186-003 Hewlett-Packard Company 6−13