recv.2 (2010 09)

r
recv(2) recv(2)
If the remote side of a connection-based socket has performed an orderly shutdown and there is no
more data to read (the socket has reached the end of its data stream),
recv() returns 0.
If the remote side of a connection-based socket has reset the connection,
recv() returns 1 and
sets
errno to [ECONNRESET].
If an error occurs,
recv() returns 1 and
errno is set to indicate the error.
If the
O_NDELAY flag is set using
fcntl() (defined in <sys/fcntl.h>
and explained in fcntl (2) and
fcntl (5)), nonblocking I/O is enabled. In this case, the
recv() request completes in one of five ways:
If there is enough data available to satisfy the entire request,
recv() completes successfully, hav-
ing read all the data, and returns the number of bytes read.
If there is not enough data to satisfy the entire request
recv() completes successfully, having read
as much data as possible, and returns the number of bytes it was able to read.
If the remote side of a connection-based socket has performed an orderly shutdown and there is no
more data to read (the socket has reached the end of its data stream),
recv() completes and
returns 0. The
recv() call will also complete and return 0 when there is no data to read. To dis-
tinguish this condition from the end of the data stream, you can use a
select() or poll() call to
check for data before calling
recv(). If the
select() or poll() call indicates that an event has
occurred on the socket, the subsequent but
recv()
call will only return 0 if the socket has reached
the end of the data stream.
If the remote side of a connection-based socket has reset the connection,
recv() returns 1 and
sets
errno to [ECONNRESET].
If an error occurs,
recv() returns 1 and errno is set to indicate the error.
If the
O_NONBLOCK or O_NDELAY flag is cleared using fcntl(), the corresponding style of nonblocking
I/O, if previously enabled, is disabled. In this case, recv() always executes completely (blocking as
necessary) and returns the number of bytes read.
Since both the
fcntl() O_NONBLOCK and O_NDELAY flags and ioctl() FIOSNBIO request are sup-
ported, some clarification on how these features interact is necessary. If the O_NONBLOCK or
O_NDELAY flag has been set, recv() requests behave accordingly, regardless of any FIOSNBIO
requests. If neither the O_NONBLOCK flag nor the O_NDELAY flag has been set, FIOSNBIO
requests
control the behavior of
recv().
By default nonblocking I/O is disabled.
select() can be used to determine when more data arrives by selecting the socket for reading.
The flags parameter can be set to
MSG_PEEK, MSG_OOB, both, or zero. If it is set to
MSG_PEEK, any
data returned to the user still is treated as if it had not been read. The next
recv() rereads the same
data. The
MSG_OOB flag is used to receive out-of-band data. For TCP SOCK_STREAM sockets, both the
MSG_PEEK and MSG_OOB flags can be set at the same time. The MSG_OOB flag value is supported for
TCP SOCK_STREAM sockets only. MSG_OOB is not supported for AF_UNIX or AF_VME_LINK sockets.
A
read() call made to a socket behaves in exactly the same way as a recv() with flags set to zero.
AF_CCITT Only
Connections in the address family AF_CCITT support message-based sockets only. Although the user
specifies connection-based communications (SOCK_STREAM), the X.25 subsystem communicates via mes-
sages. This address family does not support SOCK_DGRAM socket types.
Normally, each
recv() returns one complete X.25 message. If the socket is in nonblocking mode,
recv() behaves as described above. Note that if the user specifies len less than the actual X.25 message
size, the excess data is discarded and no error indication is returned. The size of the next available mes-
sage as well as the state of MDTF, D, and Q bits can be obtained with ioctl(X25_NEXT_MSG_STAT)
.
Connections of the address family AF_CCITT receive data in the same way as message-based connections
described above, with the following additions and exceptions:
recvfrom() is supported; however, the from and fromlen parameters are ignored (that is, it works
in the same manner as recv()).
To receive a message in fragments of the complete X.25 message, use
ioctl(X25_SET_FRAGMENT_SIZE). The state of the MDTF bit is 1 for all except the last frag-
ment of the message.
HP-UX 11i Version 3: September 2010 3 Hewlett-Packard Company 3