Manual Pages for Linux CentOS command on man readv
MyWebUniversity

Manual Pages for Linux CentOS command on man readv

READV(2) Linux Programmer's Manual READV(2)

NAME

readv, writev, preadv, pwritev - read or write data into multiple buf‐ fers SYNOPSIS

#include ssizet readv(int fd, const struct iovec *iov, int iovcnt); ssizet writev(int fd, const struct iovec *iov, int iovcnt); ssizet preadv(int fd, const struct iovec *iov, int iovcnt, offt offset); ssizet pwritev(int fd, const struct iovec *iov, int iovcnt, offt offset); Feature Test Macro Requirements for glibc (see featuretestmacros(7)): preadv(), pwritev(): BSDSOURCE DESCRIPTION The readv() system call reads iovcnt buffers from the file associated with the file descriptor fd into the buffers described by iov ("scatter input"). The writev() system call writes iovcnt buffers of data described by iov to the file associated with the file descriptor fd ("gather output"). The pointer iov points to an array of iovec structures, defined in as: struct iovec { void *iovbase; /* Starting address */ sizet iovlen; /* Number of bytes to transfer */ }; The readv() system call works just like read(2) except that multiple buffers are filled. The writev() system call works just like write(2) except that multiple buffers are written out. Buffers are processed in array order. This means that readv() com‐ pletely fills iov[0] before proceeding to iov[1], and so on. (If there is insufficient data, then not all buffers pointed to by iov may be filled.) Similarly, writev() writes out the entire contents of iov[0] before proceeding to iov[1], and so on. The data transfers performed by readv() and writev() are atomic: the data written by writev() is written as a single block that is not intermingled with output from writes in other processes (but see pipe(7) for an exception); analogously, readv() is guaranteed to read a contiguous block of data from the file, regardless of read operations performed in other threads or processes that have file descriptors referring to the same open file description (see open(2)). preadv() and pwritev() The preadv() system call combines the functionality of readv() and pread(2). It performs the same task as readv(), but adds a fourth argument, offset, which specifies the file offset at which the input operation is to be performed. The pwritev() system call combines the functionality of writev() and pwrite(2). It performs the same task as writev(), but adds a fourth argument, offset, which specifies the file offset at which the output operation is to be performed. The file offset is not changed by these system calls. The file referred to by fd must be capable of seeking. RETURN VALUE On success, readv() and preadv() return the number of bytes read; writev() and pwritev() return the number of bytes written. On error,

-1 is returned, and errno is set appropriately. ERRORS The errors are as given for read(2) and write(2). Furthermore, preadv() and pwritev() can also fail for the same reasons as lseek(2). Additionally, the following error is defined: EINVAL The sum of the iovlen values overflows an ssizet value. Or, the vector count iovcnt is less than zero or greater than the permitted maximum. VERSIONS preadv() and pwritev() first appeared in Linux 2.6.30; library support was added in glibc 2.10. CONFORMING TO readv(), writev(): 4.4BSD (these system calls first appeared in

4.2BSD), POSIX.1-2001. Linux libc5 used sizet as the type of the iovcnt argument, and int as the return type. preadv(), pwritev(): nonstandard, but present also on the modern BSDs. NOTES Linux notes

POSIX.1-2001 allows an implementation to place a limit on the number of items that can be passed in iov. An implementation can advertise its limit by defining IOVMAX in or at run time via the return value from sysconf(SCIOVMAX). On Linux, the limit advertised by these mechanisms is 1024, which is the true kernel limit. However, the glibc wrapper functions do some extra work if they detect that the underlying kernel system call failed because this limit was exceeded. In the case of readv() the wrapper function allocates a temporary buf‐ fer large enough for all of the items specified by iov, passes that buffer in a call to read(2), copies data from the buffer to the loca‐ tions specified by the iovbase fields of the elements of iov, and then frees the buffer. The wrapper function for writev() performs the anal‐ ogous task using a temporary buffer and a call to write(2). BUGS It is not advisable to mix calls to readv() or writev(), which operate on file descriptors, with the functions from the stdio library; the results will be undefined and probably not what you want. EXAMPLE The following code sample demonstrates the use of writev(): char *str0 = "hello "; char *str1 = "world\n"; struct iovec iov[2]; ssizet nwritten; iov[0].iovbase = str0; iov[0].iovlen = strlen(str0); iov[1].iovbase = str1; iov[1].iovlen = strlen(str1); nwritten = writev(STDOUTFILENO, iov, 2); SEE ALSO pread(2), read(2), write(2) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2010-11-17 READV(2)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™