1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 2006 Jens Axboe
4 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
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 .\" Japanese Version Copyright (c) 2007 Akihiro MOTOKI
27 .\" all rights reserved.
28 .\" Translated 2007-02-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
29 .\" Updated 2008-11-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.13
31 .TH SPLICE 2 2009-09-15 "Linux" "Linux Programmer's Manual"
33 splice \- ¥Ñ¥¤¥×¤È¤Î´Ö¤Ç¥Ç¡¼¥¿¤ò·Ñ¤®¹ç¤ï¤»¤ë
36 .B #define _GNU_SOURCE
39 .BI "ssize_t splice(int " fd_in ", loff_t *" off_in ", int " fd_out ,
40 .BI " loff_t *" off_out ", size_t " len \
41 ", unsigned int " flags );
43 .\" Return type was long before glibc 2.7
46 ¤Ï¡¢¥«¡¼¥Í¥ë¥¢¥É¥ì¥¹¶õ´Ö¤È¥æ¡¼¥¶¥¢¥É¥ì¥¹¶õ´Ö¤È¤Î´Ö¤Î¥³¥Ô¡¼¤òȼ¤ï¤º¤Ë¡¢
47 2 ¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿´Ö¤Ç¥Ç¡¼¥¿¤Î°ÜÆ°¤ò¹Ô¤¦¡£
48 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
50 ¤«¤é¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
55 2 ¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¤¦¤Á°ì¤Ä¤Ï
56 ¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
59 ¤¬¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç¡¢
61 ¤Ï NULL ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
63 ¤¬¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤ª¤é¤º¡¢
67 ¤Î¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤«¤é»Ï¤Þ¤ë¥Ð¥¤¥È¤òÆɤ߽Ф¹¡£
68 ¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤ÏŬÀÚ¤ËÄ´À°¤µ¤ì¤ë¡£
70 ¤¬¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤ª¤é¤º¡¢
76 ¤«¤é¤Î¥Ç¡¼¥¿Æɤ߽Ф·¤ò³«»Ï¤¹¤ëÀèƬ¥ª¥Õ¥»¥Ã¥È¤ò³ÊǼ¤·¤¿¥Ð¥Ã¥Õ¥¡
77 ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢
79 ¤Î¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
83 ¤Ë´Ø¤·¤Æ¤âƱÍͤǤ¢¤ë¡£
86 °ú¤¿ô¤Ë¤Ï¡¢°Ê²¼¤ÎÃͤΠ0 ¸Ä°Ê¾å¤Î¥Ó¥Ã¥Èñ°Ì¤ÎÏÀÍýϤò
90 ¥Ú¡¼¥¸¤Î¥³¥Ô¡¼¤Ç¤Ê¤¯°ÜÆ°¤ò»î¤ß¤ë¡£
91 ¤³¤ì¤Ï¥«¡¼¥Í¥ë¤ËÂФ¹¤ë¥Ò¥ó¥È¤Ç¤·¤«¤Ê¤¤¡£
92 ¤Ä¤Þ¤ê¡¢¥«¡¼¥Í¥ë¤¬¥Ñ¥¤¥×¤«¤é¥Ú¡¼¥¸¤ò°ÜÆ°¤Ç¤¤Ê¤¤¾ì¹ç¤ä¡¢
93 ¥Ñ¥¤¥×¥Ð¥Ã¥Õ¥¡¤¬¥Ú¡¼¥¸Á´Éô¤ò»²¾È¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢
94 ¥Ú¡¼¥¸¤Î¥³¥Ô¡¼¤¬¹Ô¤ï¤ì¤ë¤³¤È¤â¤¢¤ë¡£
95 ¤³¤Î¥Õ¥é¥°¤ÎºÇ½é¤Î¼ÂÁõ¤Ë¤Ï¥Ð¥°¤¬¤¢¤Ã¤¿¡£¤½¤Î¤¿¤á¡¢
96 Linux 2.6.21 °Ê¹ß¤Ç¤Ï¤³¤Î¥Õ¥é¥°¤ÎÁàºî¤Ï¤Ç¤¤Ê¤¤¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë
99 ¥³¡¼¥ë¤Ç¤³¤Î¥Õ¥é¥°¤ò»ØÄꤹ¤ë¤³¤È¤Ïº£¤âǧ¤á¤é¤ì¤Æ¤¤¤ë)¡£
100 ¾Íè¡¢Àµ¤·¤¤¼ÂÁõ¤¬¹Ô¤ï¤ì¤ë¤³¤È¤À¤í¤¦¡£
103 Æþ½ÐÎÏ»þ¤ËÄä»ß (block) ¤·¤Ê¤¤¡£
104 ¤³¤Î¥Õ¥é¥°¤ò»ØÄꤹ¤ë¤È¡¢
105 splice ¤Ë¤è¤ë¥Ñ¥¤¥×Áàºî¤òÈóÄä»ß¥â¡¼¥É (nonblocking) ¤Ç
106 ¹Ô¤ª¤¦¤È¤¹¤ë¤¬¡¢¤½¤Î¾ì¹ç¤Ç¤â
108 ¤ÏÄä»ß¤¹¤ë¤³¤È¤â¤¢¤ë¡£¤Ê¤¼¤Ê¤é¡¢¥Ç¡¼¥¿¤Î¤ä¤ê¼è¤ê¤ò¹Ô¤¦
109 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï
111 ¥Õ¥é¥°¤ò¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç) Ää»ß¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¤«¤é¤Ç¤¢¤ë¡£
114 ¤³¤Î¸å¤Î splice ¤Ç¤µ¤é¤ËžÁ÷¤µ¤ì¤ë¥Ç¡¼¥¿¤¬¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
117 ¤¬¥½¥±¥Ã¥È¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç¤ËÍÍѤʥҥó¥È¤È¤Ê¤ë
135 ¤Ï¥Ñ¥¤¥×¤«¤é½Ð¤·Æþ¤ì¤·¤¿¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£
136 ÊÖ¤êÃÍ 0 ¤Ï¥Ç¡¼¥¿¤ÎžÁ÷¤¬¹Ô¤ï¤Ê¤«¤Ã¤¿¤³¤È¤ò¼¨¤¹¡£
137 ¤³¤Î¾ì¹ç¡¢½èÍý¤òÄä»ß (block) ¤·¤Æ¤â̵°ÕÌ£¤Ç¤¢¤ë¡£
140 ¤¬»²¾È¤¹¤ë¥Ñ¥¤¥×¤Î½ñ¤¹þ¤ß¦¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¼Ô¤¬¤¤¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£
146 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹ÃͤòÀßÄꤹ¤ë¡£
150 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î°ìÊý¤Þ¤¿¤ÏξÊý¤¬Í¸ú¤Ç¤Ï¤Ê¤¤¡¢
151 ¤â¤·¤¯¤ÏŬÀÚ¤Ê read-write ¥â¡¼¥É¤Ç¤Ï¤Ê¤¤¡£
154 ÂоݤΥե¡¥¤¥ë¥·¥¹¥Æ¥à¤¬ splice ¤ËÂбþ¤·¤Æ¤¤¤Ê¤¤¡¢
155 ¤Þ¤¿¤ÏÂоݤΥե¡¥¤¥ë¤¬Äɵ¥â¡¼¥É¤Ç¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡¢
156 .\" Äɵ¥â¡¼¥É¤Ç¤Î¥¨¥é¡¼¤Ï 2.6.27 °Ê¹ß¤ÇȯÀ¸¤¹¤ë¡£
157 .\" ¤½¤ì¤è¤êÁ°¤Î¥«¡¼¥Í¥ë¤Ç¤ÏÄɵ¥â¡¼¥É¤Ç¤Î splice() ¤ÏÀµ¤·¤¯Æ°ºî¤·¤Ê¤¤¡£
158 ¤Þ¤¿¤Ï¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¤É¤Á¤é¤â¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤Ê¤¤¡¢
159 ¤Þ¤¿¤Ï seek ¤Ç¤¤Ê¤¤¥Ç¥Ð¥¤¥¹¤ËÂФ·¤Æ¥ª¥Õ¥»¥Ã¥È¤¬»ØÄꤵ¤ì¤¿¡£
168 ¤Î¤¤¤º¤ì¤«¤¬ NULL ¤Ç¤Ï¤Ê¤¤¤¬¡¢Âбþ¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬
169 ¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤ë¡£
172 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux 2.6.17 ¤Ç½é¤á¤ÆÅо줷¤¿¡£
174 ¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux ¸ÇͤǤ¢¤ë¡£
180 ¤ò»È¤¦¤È¡¢¥æ¡¼¥¶¶õ´Ö¥×¥í¥°¥é¥à¤ÏǤ°Õ¤Î¥«¡¼¥Í¥ë¥Ð¥Ã¥Õ¥¡¤ËÂФ¹¤ë
181 ´°Á´¤ÊÀ©¸æ¤¬¤Ç¤¤ë¡£¥«¡¼¥Í¥ë¥Ð¥Ã¥Õ¥¡¤Ï¡¢¥Ñ¥¤¥×¤Ë»ÈÍѤµ¤ì¤Æ¤¤¤ë¤Î¤È
182 Ʊ¼ï¤Î¥Ð¥Ã¥Õ¥¡¤ò»È¤Ã¤Æ¥«¡¼¥Í¥ëÆâ¤Ë¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¡£
183 Âç¤Þ¤«¤Ë¤¤¤¦¤È¡¢¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï°Ê²¼¤Î»Å»ö¤ò¹Ô¤¦:
186 ¥Ð¥Ã¥Õ¥¡¤«¤éǤ°Õ¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ä¡¢¤½¤ÎµÕÊý¸þ¡¢
187 ¤â¤·¤¯¤Ï¤¢¤ë¥Ð¥Ã¥Õ¥¡¤«¤éÊ̤ΥХåե¡¤Ø¤Î¡¢¥Ç¡¼¥¿°ÜÆ°¤ò¹Ô¤¦¡£
190 ¤¢¤ë¥Ð¥Ã¥Õ¥¡¤«¤éÊ̤ΥХåե¡¤Ø¤Î¥Ç¡¼¥¿¡Ö¥³¥Ô¡¼¡×¤ò¹Ô¤¦¡£
193 ¥æ¡¼¥¶¶õ´Ö¤«¤é¥Ð¥Ã¥Õ¥¡¤Ø¤Î¥Ç¡¼¥¿¡Ö¥³¥Ô¡¼¡×¤ò¹Ô¤¦¡£
195 ¤³¤³¤Ç¤Ï¥³¥Ô¡¼¤ÎÏäò¤·¤Æ¤¤¤ë¤¬¡¢¼ÂºÝ¤Î¥³¥Ô¡¼¤Ï°ìÈÌŪ¤Ë²óÈò¤µ¤ì¤ë¡£
196 ¥«¡¼¥Í¥ë¤Ï¡¢¥Ñ¥¤¥×¡¦¥Ð¥Ã¥Õ¥¡¤ò¥«¡¼¥Í¥ë¥á¥â¥ê¤Î¥Ú¡¼¥¸¤Ø¤Î¥Ý¥¤¥ó¥¿½¸¹ç¤È¤·¤Æ
197 ¼ÂÁõ¤·¡¢¥Ú¡¼¥¸¤Ø¤Î»²¾È²ó¿ô¤ò´ÉÍý¤¹¤ë¤³¤È¤Ç¡¢¤³¤ì¤ò¼Â¸½¤·¤Æ¤¤¤ë¡£
198 ¥«¡¼¥Í¥ë¤Ï¡¢ÂоݤȤʤë¥Ú¡¼¥¸¤ò»²¾È¤¹¤ë (½ÐÎϥХåե¡ÍѤÎ) ¥Ý¥¤¥ó¥¿¤ò
199 ¿·µ¬¤ËºîÀ®¤¹¤ë¤³¤È¤Ç¥Ð¥Ã¥Õ¥¡Æâ¤Î¥Ú¡¼¥¸¤Î¡Ö¥³¥Ô¡¼¡×¤òºîÀ®¤·¡¢
200 ¤½¤Î¥Ú¡¼¥¸¤Î»²¾È²ó¿ô¤òÁý¤ä¤¹¡£¤Ä¤Þ¤ê¡¢¥Ý¥¤¥ó¥¿¤À¤±¤¬¥³¥Ô¡¼¤µ¤ì¡¢
201 ¥Ð¥Ã¥Õ¥¡¤Î¥Ú¡¼¥¸¤Ï¥³¥Ô¡¼¤µ¤ì¤Ê¤¤¡£
203 .\" Linus: Now, imagine using the above in a media server, for example.
204 .\" Let's say that a year or two has passed, so that the video drivers
205 .\" have been updated to be able to do the splice thing, and what can
208 .\" - splice from the (mpeg or whatever - let's just assume that the video
209 .\" input is either digital or does the encoding on its own - like they
210 .\" pretty much all do) video input into a pipe (remember: no copies - the
211 .\" video input will just DMA directly into memory, and splice will just
212 .\" set up the pages in the pipe buffer)
213 .\" - tee that pipe to split it up
214 .\" - splice one end to a file (ie "save the compressed stream to disk")
215 .\" - splice the other end to a real-time video decoder window for your
216 .\" real-time viewing pleasure.
218 .\" Linus: Now, the advantage of splice()/tee() is that you can
219 .\" do zero-copy movement of data, and unlike sendfile() you can
220 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
221 .\" than just sending the data to somebody else: you can duplicate
222 .\" the data and choose to forward it to two or more different
223 .\" users - for things like logging etc.).
232 .BR feature_test_macros (7)