1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" and Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified Sat Jul 24 18:34:44 1993 by Rik Faith (faith@cs.unc.edu)
27 .\" Merged readv.[23], 2002-10-17, aeb
28 .\" 2007-04-30 mtk, A fairly major rewrite to fix errors and
31 .\" 1996-04-12 Tom Bjorkholm <tomb@mydata.se>
32 .\" First version written
33 .\" Modified Tue Oct 22 17:41:07 1996 by Eric S. Raymond <esr@thyrsus.com>
35 .\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya
36 .\" all rights reserved.
37 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
38 .\" Updated 1999-04-03, HANATAKA Shinya
39 .\" Updated 2003-01-14, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
40 .\" Updated 2005-10-07, Akihiro MOTOKI
41 .\" Updated 2007-06-01, Akihiro MOTOKI, LDP v2.50
43 .\"WORD: vector ¥Ù¥¯¥¿ (vector)
44 .\"WORD: file descriptor ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
45 .\"WORD: buffer ¥Ð¥Ã¥Õ¥¡
47 .TH READV 2 2002-10-17 "Linux" "Linux Programmer's Manual"
49 .\"O readv, writev \- read or write data into multiple buffers
51 readv, writev \- Ê£¿ô¤Î¥Ð¥Ã¥Õ¥¡¤Ø¤ÎÆɤ߽ñ¤¤ò¹Ô¤Ê¤¦
55 .B #include <sys/uio.h>
57 .BI "ssize_t readv(int " fd ", const struct iovec *" iov ", int " iovcnt );
59 .BI "ssize_t writev(int " fd ", const struct iovec *" iov ", int " iovcnt );
67 .\"O buffers from the file associated with the file descriptor
69 .\"O into the buffers described by
71 .\"O ("scatter input").
73 ´Ø¿ô¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
75 ¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥¡¥¤¥ë¤«¤é¡¢
77 ¸Ä¤Î¥Ð¥Ã¥Õ¥¡Ê¬¤Î¥Ç¡¼¥¿¤òÆɤ߹þ¤ß¡¢
79 ¤Ç»ØÄꤵ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤Ë³ÊǼ¤¹¤ë
80 ("scatter input";¡Ö¤Ð¤é¤Þ¤ÆþÎÏ¡×)¡£
84 .\"O function writes at most
86 .\"O buffers described by
88 .\"O to the file associated with the file descriptor
90 .\"O ("gather output").
94 ¤Ç»ØÄꤵ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤«¤éºÇÂç
96 ¸Ä¤Î¥Ð¥Ã¥Õ¥¡Ê¬¤Î¥Ç¡¼¥¿¤ò¼è¤ê½Ð¤·¡¢
97 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
99 ¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥¡¥¤¥ë¤Ë½ñ¤¹þ¤à
100 ("gather output";¡Ö¤«¤½¸¤á½ÐÎÏ¡×)¡£
104 .\"O points to an array of
114 ¹½Â¤ÂΤÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
118 ¤Ç°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
124 void *iov_base; /* Starting address */
125 size_t iov_len; /* Number of bytes to transfer */
132 .\"O function works just like
134 .\"O except that multiple buffers are filled.
136 ´Ø¿ô¤Ï¡¢Ê£¿ô¤Î¥Ð¥Ã¥Õ¥¡¤Ë¥Ç¡¼¥¿¤òÆɤ߹þ¤àÅÀ¤ò½ü¤¤¤Æ
138 ¤ÈÁ´¤¯Æ±ÍͤÎÆ°ºî¤ò¹Ô¤¦¡£
142 .\"O function works just like
144 .\"O except that multiple buffers are written out.
146 ´Ø¿ô¤Ï¡¢Ê£¿ô¤Î¥Ð¥Ã¥Õ¥¡¤Î¥Ç¡¼¥¿¤ò½ñ¤½Ð¤¹ÅÀ°Ê³°¤Ï
148 ¤ÈÁ´¤¯Æ±ÍͤÎÆ°ºî¤ò¹Ô¤¦¡£
150 .\"O Buffers are processed in array order.
153 .\"O completely fills
155 .\"O before proceeding to
158 .\"O (If there is insufficient data, then not all buffers pointed to by
163 .\"O writes out the entire contents of
165 .\"O before proceeding to
168 ¥Ð¥Ã¥Õ¥¡¤ÏÇÛÎó¤Î½ç½ø¤Ç½èÍý¤µ¤ì¤ë¡£¤³¤ì¤Ï¡¢
172 ¤¬´°Á´¤Ë°ìÇդˤʤë¤Þ¤Ç¥Ç¡¼¥¿¤òµÍ¤á¤Æ¤«¤é¡¢
174 ¤Ê¤É¤Ë¿Ê¤à¤³¤È¤ò°ÕÌ£¤¹¤ë
175 (¥Ç¡¼¥¿¤¬½½Ê¬¤Ê¤¤¾ì¹ç¤Ï¡¢
177 ¤¬»Ø¤¹¥Ð¥Ã¥Õ¥¡¤Î¤¤¤º¤ì¤â°ìÇդˤʤé¤Ê¤¤)¡£
182 ¤ÎÆâÍƤòÁ´Éô½ñ¤½Ð¤·¤Æ¤«¤é
186 .\"O The data transfers performed by
190 .\"O are atomic: the data written by
192 .\"O is written as a single block that is not intermingled with output
193 .\"O from writes in other processes (but see
195 .\"O for an exception);
198 .\"O is guaranteed to read a contiguous block of data from the file,
199 .\"O regardless of read operations performed in other threads or processes
200 .\"O that have file descriptors referring to the same open file description
206 ¤Ë¤è¤ë¥Ç¡¼¥¿Å¾Á÷¤Ï atomic ¤Ë¹Ô¤ï¤ì¤ë¡£¤Ä¤Þ¤ê¡¢
208 ¤Ë¤è¤ë¥Ç¡¼¥¿½ñ¤¹þ¤ß¤Ï°ì¤Ä¤Î¥Ö¥í¥Ã¥¯¤È¤·¤Æ¹Ô¤ï¤ì¡¢Â¾¤Î¥×¥í¥»¥¹¤Î
209 write ¤Ë¤è¤ë½ñ¤¹þ¤ß¤Èº®¤¶¤ê¹ç¤¦¤³¤È¤Ï¤Ê¤¤
212 ¤ò»²¾È¤Î¤³¤È)¡£Æ±Íͤˡ¢
214 ¤Ï¥Õ¥¡¥¤¥ë¤«¤éϢ³¤¹¤ë¥Ç¡¼¥¿¥Ö¥í¥Ã¥¯¤¬Æɤ߽Ф¹¤³¤È¤¬Êݾڤµ¤ì¡¢
215 Ʊ¤¸¥Õ¥¡¥¤¥ëµ½Ò (file description;
217 »²¾È) ¤ò»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò»ý¤Ä¾¤Î¥¹¥ì¥Ã¥É¤ä¥×¥í¥»¥¹¤¬
218 ¼Â¹Ô¤·¤¿ read Áàºî¤Î±Æ¶Á¤ò¼õ¤±¤ë¤³¤È¤Ï¤Ê¤¤¡£
219 .\"O .SH "RETURN VALUE"
223 .\"O function returns the number of bytes read; the
225 .\"O function returns the number of bytes written.
226 .\"O On error, \-1 is returned, and \fIerrno\fP is set appropriately.
229 ´Ø¿ô¤ÏÆɤ߹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤·¡¢
231 ´Ø¿ô¤Ï½ñ¤¹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£
232 ¥¨¥é¡¼¤Î¾ì¹ç \-1 ¤òÊÖ¤·¡¢\fIerrno\fP ¤òŬÀÚ¤ËÀßÄꤹ¤ë¡£
235 .\"O The errors are as given for
242 ¤ÈƱ¤¸¥¨¥é¡¼¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
243 .\"O Additionally the following error is defined:
244 ¤µ¤é¤Ë°Ê²¼¤Î¥¨¥é¡¼¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
249 .\"O values overflows an
252 .\"O Or, the vector count \fIiovcnt\fP is less than zero or greater than the
253 .\"O permitted maximum.
257 ¤ÎÈϰϤò¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤·¤¿¡£¤â¤·¤¯¤Ï¡¢
258 ¥Ù¥¯¥¿¿ô \fIiovcnt\fP ¤¬ 0 ¤è¤ê¾®¤µ¤¤¤«µö²Ä¤µ¤ì¤¿ºÇÂçÃͤè¤ê¤âÂ礤«¤Ã¤¿¡£
259 .\"O .SH "CONFORMING TO"
265 .\"O functions first appeared in 4.2BSD), POSIX.1-2001.
266 .\"O Linux libc5 used \fIsize_t\fP as the type of the \fIiovcnt\fP argument,
267 .\"O and \fIint\fP as return type for these functions.
268 .\"O .\" The readv/writev system calls were buggy before Linux 1.3.40.
269 .\"O .\" (Says release.libc.)
274 ´Ø¿ô¤Ï 4.2BSD ¤ÇºÇ½é¤Ë¸½¤ï¤ì¤¿)¡¢POSIX.1-2001¡£
275 Linux libc5 ¤Ç¤Ï \fIiovcnt\fP °ú¤¿ô¤Î·¿¤È¤·¤Æ \fIsize_t\fP ¤ò¡¢
276 ¤³¤ì¤é¤Î´Ø¿ô¤ÎÊÖ¤êÃͤȤ·¤Æ \fIint\fP ¤ò»ÈÍѤ·¤Æ¤¤¤¿¡£
277 .\" readv/writev ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux 1.3.40 °ÊÁ°¤Ï¥Ð¥°¤À¤é¤±¤Ç¤¢¤Ã¤¿
278 .\" (¤È release.libc ¤Ë½ñ¤«¤ì¤Æ¤¤¤ë)¡£
283 .\"O POSIX.1-2001 allows an implementation to place a limit on
284 .\"O the number of items that can be passed in
286 .\"O An implementation can advertise its limit by defining
290 .\"O or at run time via the return value from
291 .\"O .IR sysconf(_SC_IOV_MAX) .
292 .\"O On Linux, the limit advertised by these mechanisms is 1024,
293 .\"O which is the true kernel limit.
296 ¤ÇÅϤ¹¤³¤È¤¬¤Ç¤¤ëÍ×ÁÇ¿ô¤Ë¾å¸Â¤òÀߤ±¤ë¼ÂÁõ¤¬Ç§¤á¤é¤ì¤Æ¤¤¤ë¡£
301 ¤òÄêµÁ¤¹¤ë¤³¤È¤ä¡¢¼Â¹Ô»þ¤Ë
302 .I sysconf(_SC_IOV_MAX)
303 ¤ÎÊÖ¤êÃÍ·Ðͳ¤Ç¡¢¤³¤Î¾å¸Â¤ò¹¹ð¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
304 Linux ¤Ç¤Ï¡¢¤³¤Î»ÅÁȤߤˤè¤ê¹¹ð¤µ¤ì¤ë¾å¸Â¤Ï 1024 ¤Ç¤¢¤ê¡¢
305 ¤³¤ÎÃͤϥ«¡¼¥Í¥ë¤Ç¤Î¾å¸Â¤½¤Î¤â¤Î¤Ç¤¢¤ë¡£
306 .\"O However, the glibc wrapper functions do some extra work if
307 .\"O they detect that the underlying kernel system call failed because this
308 .\"O limit was exceeded.
311 .\"O the wrapper function allocates a temporary buffer large enough
312 .\"O for all of the items specified by
314 .\"O passes that buffer in a call to
316 .\"O copies data from the buffer to the locations specified by the
318 .\"O fields of the elements of
320 .\"O and then frees the buffer.
321 .\"O The wrapper function for
323 .\"O performs the analogous task using a temporary buffer and a call to
325 °ìÊý¤Ç¡¢glibc ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï¡¢¤½¤Î´Ø¿ô¤ÎÆâÉô¤Ç¸Æ¤Ð¤ì¤ë¥«¡¼¥Í¥ë¡¦
326 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬¤³¤Î¾å¸Â¤òĶ²á¤·¤Æ¼ºÇÔ¤·¤¿¤³¤È¤ò¸¡½Ð¤¹¤ë¤È¡¢
329 ¤Î¾ì¹ç¡¢¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï
331 ¤Ç»ØÄꤵ¤ì¤¿Á´¤Æ¤ÎÍ×ÁǤò³ÊǼ¤Ç¤¤ëÂ礤µ¤Î°ì»þ¥Ð¥Ã¥Õ¥¡¤ò³ä¤êÅö¤Æ¡¢
333 ¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë¤½¤Î¥Ð¥Ã¥Õ¥¡¤òÅϤ·¡¢
334 ¤½¤Î¥Ð¥Ã¥Õ¥¡¤Î¥Ç¡¼¥¿¤ò
338 ¥Õ¥£¡¼¥ë¥É¤¬»ØÄꤹ¤ë¾ì½ê¤Ë¥³¥Ô¡¼¤·¤Æ¤«¤é¡¢
339 ¤½¤Î¥Ð¥Ã¥Õ¥¡¤ò²òÊü¤¹¤ë¡£
341 ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤â¡¢Æ±¤¸¤è¤¦¤Ë°ì»þ¥Ð¥Ã¥Õ¥¡¤ò»È¤Ã¤Æ
346 .\"O It is not advisable to mix calls to functions like
350 .\"O which operate on file descriptors, with the functions from the stdio
351 .\"O library; the results will be undefined and probably not what you want.
355 ¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ¹¤ëÁàºî¤ò¹Ô¤¦´Ø¿ô¤È¡¢
356 ɸ½àÆþ½ÐÎϥ饤¥Ö¥é¥ê¤Î´Ø¿ô¤ò¤´¤Á¤ã¤Þ¤¼¤Ë¤·¤Æ¸Æ¤Ö¤Î¤Ï¤ªÁ¦¤á¤·¤Ê¤¤¡£
357 ¤É¤ó¤Ê·ë²Ì¤Ë¤Ê¤ë¤«¤ÏÄêµÁ¤µ¤ì¤Æ¤ª¤é¤º¡¢
358 ¤ª¤½¤é¤¯Íߤ·¤¤·ë²Ì¤ÏÆÀ¤é¤ì¤Ê¤¤¤À¤í¤¦¡£
361 .\"O The following code sample demonstrates the use of
363 °Ê²¼¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï
365 ¤Î»ÈÍÑÊýË¡¤ò¼¨¤¹¤â¤Î¤Ç¤¢¤ë¡£
369 char *str0 = "hello ";
370 char *str1 = "world\\n";
374 iov[0].iov_base = str0;
375 iov[0].iov_len = strlen(str0);
376 iov[1].iov_base = str1;
377 iov[1].iov_len = strlen(str1);
379 nwritten = writev(STDOUT_FILENO, iov, 2);