The readv() socket call receives data on a socket into a set of buffers.
Syntax
#include <types.h> #include <sys/uio.h> int readv(s, iov, iovcnt) int s; struct iovec *iov; int iovcnt;
Parameters
s
Description
This call reads data on a socket with descriptor s and stores it in a set of buffers. The data is scattered into the buffers specified by iov[0]...iov[iovcnt-1]. The iovec structure is defined in <SYS/UIO.H> and contains the following fields:
Field
The readv() call applies only to connected sockets. For information on how to use readv() with datagram and raw sockets, see Datagram or Raw Sockets.
TCP/IP alters iov_base and iov_len for each element in the input struct iovec array. iov_base will point to the next character of the processed (sent or received) data on the original buffer, and iov_len will become (input value - processed length). Thus if only partial data has been sent or received and the application expects more data to send or receive, it can pass the same iovec structure back in a subsequent call.
This call returns up to the number of bytes in the buffers pointed to by the iov parameter. This number is the sum of all iov_len fields. If less than the number of bytes requested is available, the call returns the number currently available. If data is not available at the socket with descriptor s, the readv() call waits for data to arrive and blocks the caller, unless the socket is in nonblocking mode. See ioctl() for a description of how to set nonblocking mode. The UDP sockets can send and receive datagrams as large as 32739 bytes (32 * 1024 -1 - IP header (20 bytes) - UDP header (8 bytes)).
Return Values
When successful, the number of bytes of data received into the buffer is returned. The value -1 indicates an error. You can get the specific error code by calling sock_errno() or psock_errno().
sock_errno() Value
Related Calls
accept() accept_and_recv()
connect()
getsockopt()
ioctl()
recv()
recvfrom()
recvmsg()
select()
send()
sendto()
setsockopt()
so_cancel()
sock_errno()
socket()
writev()