readv

Reads data from a socket and stores it in multiple user buffers as specified.

Library:LibC
Classification:BSD
Service:Networking

Syntax

  #include <sys/uio.h> 
   
  ssize_t readv (
     int                   fildes,
     const struct iovec   *iov,
     int                   iovcnt);
  

Parameters

fildes

(IN) Specifies the file handle from which data is to be read.

iov

(IN) Points to the iovec structure containing the base address and the length of an area in memory where data can be stored.

iovcnt

(IN) Specifies the number of buffers in the iov array.

Return Values

If successful, returns either 0 or the number of bytes actually read. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

The socket file handle is invalid for reading.

9

EINVAL

The socket is not in a listening state.

35

EWOULDBLOCK

The socket is marked nonblocking, and no connections are present to be accepted.

Remarks

The readv function scatters the input data into the iovcnt buffers specified by the iov array.

Each iovec entry specifies the base address and length of an area in memory where data can be placed. The readv function always fills an area completely before proceeding to the next.

The system guarantees to read the number of bytes requested if there are that many bytes left before the EOF. If the returned value is 0, the peer has closed the connection and no more data is received.

To read out-of-band data from a TCP socket by calling read, the setsockopt SO_OOBINLINE must be enabled. The client can select the exception condition to detect the arrival of a new urgent boundary (just before the out-of-band byte). You can also call ioctl with SIOCATMARK to determine whether the read request has read up to the boundary yet. The system guarantees that a single read request will not cross the urgent boundary. When SIOCATMARK is detected, the next read request returns the out-of-band byte plus as much data that will fit in the buffer.

If SO_OOBINLINE is not enabled, the client must call recv to read the out-of-band byte. The next request reads data past the urgent boundary without reading the out-of-band byte (because it was not stored with the SO_OOBINLINE option).

SIOCATMARK reveals whether the out-of-band byte is readable by either method.

The readv function can also read messages from a SOCK_DGRAM socket, but you should call recv. These two functions are identical, except that flags is not available.

See Also