Jump to: navigation, search

Table of Contents >> Programmer's Reference

#include <trsocket.h>

int readv (
int socketDescriptor,
struct iovec * iov,
int iovcnt

Function Description

readv() functions as a scatter read because the received data can be placed in multiple buffers. readv() attempts to read data from the socket socketDescriptor and places the input data into the iovcnt buffers specified by the members of the iov array: iov[0], iov[1], ..., iov[iovcnt-1].

The iovec structure contains the following members:

caddr_t  iov_base;
int      iov_len;

Each iovec entry specifies the base address and length of an area in memory where data should be placed. readv() always fills one buffer completely before proceeding to the next. On success, readv() returns the number of bytes actually read and placed in the buffer; this number may be less than the total of all of the iov_len values. A value of 0 is returned when an end-of-file has been reached.


  • socketDescriptor
    The socket descriptor from which to read data.
  • iov
    The list of buffers to put the received data in.
  • iovcnt
    The number of buffers in the list.

Return Values

  • > 0
    Number of bytes actually read from the socket.

Note Note: TM_SOCKET_ERROR means that this socket call has failed and the errorCode has been set on the socket itself.

To retrieve the socket error the user must call tfGetSocketError(socketDescriptor).

Possible socket errors

    The socket descriptor is invalid.
    One of the following:
  • iovcnt is 0 or less than zero.
  • The sum of iov_len values overflowed an integer.
    Insufficient memory to complete the operation.
    The socket is marked as non-blocking and no data is available to be read.
    The peer has closed the connection and there is no more data to be read (TCP socket only).
    The socket is not connected.

Table of Contents >> Programmer's Reference