readv()

The readv() call reads data on a socket with descriptor s and stores it in a set of buffers. The readv() call applies to connected sockets only.

#include <manifest.h>
#include <socket.h>
#include <bsdtypes.h>
#include <uio.h>
 
int readv(int s, struc iovec *iov, int iovcnt)
Parameter
Description
s
The socket descriptor.
iov
Points to an iovec structure.
iovcnt
The number of buffers pointed to by the iov parameter.
The data is scattered into the buffers specified by iov[0]…iov[iovcnt-1]. The iovec structure is defined in UIO.H and contains the following variables:
Variable
Description
iov_base
Points to the buffer.
iov_len
The length of the buffer.
The readv() call applies only to connected sockets.

This call returns up to len bytes of data. If less than the number of bytes requested is available, the call returns the number currently available. If data is not available for the socket s, and s is in blocking mode, the readv() call blocks the caller until data arrives. If data is not available and s is in nonblocking mode, readv() returns a -1 and sets errno to EWOULDBLOCK. See fcntl() or ioctl() for a description of how to set nonblocking mode. When a datagram packet is too long to fit in the supplied buffer, datagram sockets discard extra bytes. Stream sockets act like streams of information with no boundaries separating data. For example, if applications A and B are connected with a stream socket and Application A sends 1000 bytes, each call to this function can return 1 byte, or 10 bytes, or the entire 1000 bytes. Therefore, applications using stream sockets should place this call in a loop and call this function until all data has been received.

Return values

If successful, the number of bytes read into the buffers is returned. The value 0 indicates that the connection is closed. The value -1 indicates an error. Errno identifies the specific error.
Errno
Description
EBADF
Indicates that s is not a valid socket descriptor.
EFAULT
Using iov and iovcnt would result in an attempt to access storage outside the caller address space.
EINVAL
Iovcnt was not valid, or one of the fields in the iov array was not valid. Also returned for a NULL iov pointer.
EWOULDBLOCK
Indicates that s is in nonblocking mode and data is not available to read.

Related calls

connect(), fcntl(), getsockopt(), ioctl(), read(), recv(), recvmsg(), recvfrom(), select(), selectex(), send(), sendmsg(), sendto(), setsockopt(), socket(), write(), writev()