readv()--Read from Descriptor Using Multiple Buffers


  Syntax
 #include <sys/types.h>
 #include <sys/uio.h>

 int readv(int descriptor,
           struct iovec *io_vector[],
           int vector_length)
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

  Threadsafe: Conditional; see Usage Notes.

The readv() function is used to receive data from a file or socket descriptor. readv() provides a way for data to be stored in several different buffers (scatter/gather I/O).

See read()--Read from Descriptor for more information related to reading from a descriptor.


Parameters

descriptor
(Input) The descriptor to be read. The descriptor refers to a file or a socket.

io_vector[]
(I/O) The pointer to an array of type struct iovec. struct iovec contains a sequence of pointers to buffers in which the data to be read is stored. The structure pointed to by the io_vector parameter is defined in <sys/uio.h>.
      struct iovec {
         void      *iov_base;
         size_t   iov_len;
      }

iov_base and iov_len are the only fields in iovec used by sockets. iov_base contains the pointer to a buffer and iov_len contains the buffer length. The rest of the fields are reserved.

vector_length
(Input) The number of entries in io_vector.

Authorities

No authorization is required.


Return Value

n
readv() is successful, where n is the number of bytes read.
-1
readv() was not successful. The errno global variable is set to indicate the error.

Error Conditions

If readv() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

Error condition Additional information
[EACCES]

If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems.

This may occur if file_descriptor refers to a socket and the socket is using a connection-oriented transport service, and a connect() was previously completed. The thread, however, does not have the appropriate privileges to the objects that were needed to establish a connection. For example, the connect() required the use of an APPC device that the thread was not authorized to.

[EAGAIN]  
[EBADF]  
[EBADFID]  
[EBUSY]  
[EDAMAGE]  
[EFAULT]  
[EINTR]  
[EINVAL]

This may occur if file_descriptor refers to a socket that is using a connectionless transport service, is not a socket of type SOCK_RAW, and is not bound to an address.

The file resides in a file system that does not support large files, and the starting offset of the file exceeds 2 GB minus 2 bytes.

[EIO]  
[ENOMEM]  
[ENOTAVAIL]  
[ENOTSAFE]  
[EOVERFLOW]

The file is a regular file, nbyte is greater than 0, the starting offset is before the end-of-file and is greater than or equal to 2GB minus 2 bytes.

[ERESTART]  
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[EUNKNOWN]  

When the descriptor refers to a socket, errno could indicate one of the following errors:

Error condition Additional information
[ECONNABORTED]

This error code indicates that the transport provider ended the connection abnormally because of one of the following:

  • The retransmission limit has been reached for data that was being sent on the socket.
  • A protocol error was detected.
[ECONNREFUSED]  
[ECONNRESET]  
[EINTR]  
[ENOTCONN]  
[ETIMEDOUT]

A non-blocking connect() was previously completed that resulted in the connection timing out. No connection is established. This error code is returned only on sockets that use a connection-oriented transport service.

[EUNATCH]  
[EWOULDBLOCK]  

If interaction with a file server is required to access the object, errno could indicate one of the following errors:

Error condition Additional information
[EADDRNOTAVAIL]  
[ECONNABORTED]  
[ECONNREFUSED]  
[ECONNRESET]  
[EHOSTDOWN]  
[EHOSTUNREACH]  
[ENETDOWN]  
[ENETRESET]  
[ENETUNREACH]  
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[ETIMEDOUT]  
[EUNATCH]  


Error Messages

Message ID Error Message Text
CPE3418 E Possible APAR condition or hardware failure.
CPF3CF2 E Error(s) occurred during running of &1 API.
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.
CPFA081 E Unable to set return value or error code.
CPFA0D4 E File system error occurred. Error number &1.


Usage Notes

  1. This function will fail with error code [ENOTSAFE] when all the following conditions are true:


  2. The io_vector[] parameter is an array of struct iovec structures. When a readv() is issued, the system processes the array elements one at a time, starting with io_vector[0]. For each element, iov_len bytes of received data are placed in storage pointed to by iov_base. Data is placed in storage until all buffers are full, or until there is no more data to receive. Only the storage pointed to by iov_base is updated. No change is made to the iov_len fields. To determine the end of the data, the application program must use the following:


  3. For sockets that use a connection-oriented transport service (for example, sockets with a type of SOCK_STREAM), a returned value of zero indicates one of the following:


  4. The following applies to sockets that use a connectionless transport service (for example, a socket with a type of SOCK_DGRAM):
  5. For the file systems that do not support large files, readv() will return [EINVAL] if the starting offset exceeds 2GB minus 2 bytes, regardless of how the file was opened. For the file systems that do support large files, readv() will return [EOVERFLOW] if the starting offset exceeds 2GB minus 2 bytes and file was not opened for large file access.

  6. QFileSvr.400 File System Differences

    The largest buffer size allowed is 16 megabytes. If a larger buffer is passed, the error EINVAL will be received.

  7. QOPT File System Differences

    When reading from files on volumes formatted in Universal Disk Format (UDF), byte locks on the range being read are ignored.

  8. Using this function successfully on the /dev/null or /dev/zero character special file results in a return value of 0. In addition, the access time for the file is updated.

Related Information



API introduced: V3R1
Top | UNIX-Type APIs | APIs by category