The readv and Writev functions are used to read and write multiple non-contiguous buffers in a function call. These two functions are sometimes referred to as scatter-read and aggregate- write .
#include <sys/uio.h>ssize_t readv(intconststructint iovcnt);ssize_t writev(intconststructint iovcnt);
The second argument to these two functions is a pointer to an array of IOVEC structures:
struct iovec { void *iov_base; /* Starting address */ size_t iov_len; /* Number of bytes to transfer */};
The number of elements in the Iov Array is explained by iovcnt .
Writev to aggregate output data from a buffer in order Iov[0], iov[1] through iov[iovcnt-1], WRITEV returns the total number of bytes of output, usually equal to the sum of all buffer lengths.
READV the read data into the buffer in the same order as above, Readv always fills a buffer first, and then fills in the next, READV returns the total number of bytes read, and if there is no data to read at the end of the file, 0 is returned.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
READV and Writev functions