#include <sys.types.h>
#include <sys.socket.h>
#include <sys.uio.h>
Kernighan-Ritchie-C:
int soc_read(s, buf, nbytes);
int s;
char *buf;
int nbytes;
int soc_readv(s, iov, iovcnt);
int s;
struct iovec *iov;
int iovcnt;
ANSI-C:
int soc_read(int s, char* buf, int nbytes);
int soc_readv(int s, struct iovec* iov, int iovcnt)
Description
The soc_read() and soc_readv() functions read messages
from a stream socket s in the AF_INET or AF_INET6 address family or
from a socket s in the AF_ISO address family.
soc_read() and soc_readv() can only be used with a socket for which a connection has already been set up.
For soc_read(), the buf parameter points to the first byte of the receive buffer buf.
nbytes specifies the length (in bytes) of the receive buffer, and thus the maximum message length.
For soc_readv(), the received data is placed in a vector with the elements iov[0], iov[1], ..., iov[iovcnt-1]. The vector elements are objects of type struct iovec.
iovcnt indicates the number of vector elements.
The iovec structure is declared in <sys.uio.h> as follows:
struct iovec { caddr_t iov_base; /* buffer for auxiliary data */ int iovlen; /* buffer length */ };
The address of the vector is passed in the parameter iov. Each vector element specifies the address and length of a storage area in which soc_readv() places the data received from socket s. The soc_readv() function fills these areas with data sequentially and only moves to the next area when the current area has been totally filled.
Return value
>=0:
If successful (number of received bytes).
-1:
If errors occur. errno is set to indicate the error.
Errors indicated by errno
EBADF
The s parameter is not a valid descriptor.
EIO
There is no available user data to be read.
ENETDOWN
The connection to the network is down.
ENOTCONN
No connection exists for the socket.
EOPNOTSUPP
The socket type is not supported. The socket is not of type SOCK_STREAM.
EWOULDBLOCK
The socket is marked as non-blocking, and the requested operation would block.
EPIPE
The connection has been shut down.
See also
connect(), getsockopt(), recv(), select(), send(), soc_ioctl(), soc_read(), soc_write(), soc_writev(), socket()