.\" This manpage is Copyright (C) 2006 Jens Axboe .\" and Copyright (C) 2006 Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2007 Akihiro MOTOKI .\" all rights reserved. .\" Translated 2007-02-04, Akihiro MOTOKI .\" Updated 2008-11-10, Akihiro MOTOKI , LDP v3.13 .\" .TH SPLICE 2 2014\-12\-31 Linux "Linux Programmer's Manual" .SH 名前 splice \- パイプとの間でデータを継ぎ合わせる .SH 書式 .nf \fB#define _GNU_SOURCE\fP /* feature_test_macros(7) 参照 */ \fB#include \fP .\" Return type was long before glibc 2.7 \fBssize_t splice(int \fP\fIfd_in\fP\fB, loff_t *\fP\fIoff_in\fP\fB, int \fP\fIfd_out\fP\fB,\fP \fB loff_t *\fP\fIoff_out\fP\fB, size_t \fP\fIlen\fP\fB, unsigned int \fP\fIflags\fP\fB);\fP .fi .SH 説明 \fBsplice\fP() は、カーネルアドレス空間とユーザーアドレス空間との間のコピーを伴わずに、 2 つのファイルディスクリプター間でデータの移動を行う。 ファイルディスクリプター \fIfd_in\fP からファイルディスクリプター \fIfd_out\fP へ最大 \fIlen\fP バイトを転送する。 2 つのファイルディスクリプターのうち一つは パイプを参照していなければならない。 \fIfd_in\fP と \fIoff_in\fP には以下のルールが適用される。 .IP * 3 \fIfd_in\fP がパイプを参照している場合、 \fIoff_in\fP は NULL でなければならない。 .IP * \fIfd_in\fP がパイプを参照しておらず、かつ \fIoff_in\fP が NULL の場合、 バイトは \fIfd_in\fP の現在のファイルオフセットから読み出され、 現在のファイルオフセットは適切に調整される。 .IP * \fIfd_in\fP がパイプを参照しておらず、 \fIoff_in\fP が NULL でない場合、 \fIoff_in\fP は \fIfd_in\fP からのデータ読み出しを開始する先頭オフセットを格納したバッファー へのポインターでなければならない。この場合、 \fIfd_in\fP の現在のファイルオフセットは変更されない。 .PP \fIfd_out\fP と \fIoff_out\fP に関しても同様である。 \fIflags\fP 引き数には、以下の値の 0 個以上をビット毎の論理和の形で指定する。 .TP 1.9i \fBSPLICE_F_MOVE\fP ページのコピーでなく移動を試みる。 これはカーネルに対するヒントでしかない。 つまり、カーネルがパイプからページを移動できない場合や、 パイプバッファーがページ全部を参照していない場合は、 ページのコピーが行われることもある。 このフラグの最初の実装にはバグがあった。そのため、 Linux 2.6.21 以降ではこのフラグの操作はできないようになっている (ただし、 \fBsplice\fP() コールでこのフラグを指定することは今も認められている)。 将来、正しい実装が行われることだろう。 .TP \fBSPLICE_F_NONBLOCK\fP 入出力時に停止 (block) しない。 このフラグを指定すると、 splice によるパイプ操作を非停止モード (nonblocking) で 行おうとするが、その場合でも \fBsplice\fP() は停止することもある。なぜなら、データのやり取りを行う ファイルディスクリプターは (\fBO_NONBLOCK\fP フラグをセットされていない場合) 停止する可能性があるからである。 .TP \fBSPLICE_F_MORE\fP この後の splice でさらに転送されるデータがあることを示す。 このフラグは \fIfd_out\fP がソケットを参照している場合に有用なヒントとなる (\fBsend\fP(2) の \fBMSG_MORE\fP や \fBtcp\fP(7) の \fBTCP_CORK\fP の説明も参照)。 .TP \fBSPLICE_F_GIFT\fP \fBsplice\fP() では使用しない。 \fBvmsplice\fP(2) 参照。 .SH 返り値 成功して完了すると、 \fBsplice\fP() はパイプから出し入れしたバイト数を返す。 返り値 0 はデータの転送が行わなかったことを示す。 この場合、処理を停止 (block) しても無意味である。 なぜなら、 \fIfd_in\fP が参照するパイプの書き込み側に接続されている者がいないからである。 エラーの場合、 \fBsplice\fP() は \-1 を返し、 \fIerrno\fP にエラーを示す値を設定する。 .SH エラー .TP \fBEAGAIN\fP \fBSPLICE_F_NONBLOCK\fP が \fIflags\fP に指定されていて、かつ操作が停止するような状態であった。 .TP \fBEBADF\fP ファイルディスクリプターの一方または両方が有効ではない、 もしくは適切な read\-write モードではない。 .TP \fBEINVAL\fP .\" The append-mode error is given since 2.6.27; in earlier kernels, .\" splice() in append mode was broken 対象のファイルシステムが splice に対応していない、 または対象のファイルが追記モードでオープンされている、 またはディスクリプターのどちらもパイプを参照していない、 または seek できないデバイスに対してオフセットが指定された。 .TP \fBENOMEM\fP メモリー不足。 .TP \fBESPIPE\fP \fIoff_in\fP か \fIoff_out\fP のいずれかが NULL ではないが、対応するファイルディスクリプターが パイプを参照している。 .SH バージョン \fBsplice\fP() システムコールは Linux 2.6.17 で初めて登場した。 ライブラリによるサポートは glibc バージョン 2.5 で追加された。 .SH 準拠 このシステムコールは Linux 固有である。 .SH 注意 3 つのシステムコール (\fBsplice\fP(), \fBvmsplice\fP(2), \fBtee\fP(2)) を使うと、ユーザー空間プログラムは任意のカーネルバッファーに対する 完全な制御ができる。カーネルバッファーは、パイプに使用されているのと 同種のバッファーを使ってカーネル内に実装されている。 大まかにいうと、これらのシステムコールは以下の仕事を行う: .TP 1.2i \fBsplice\fP() バッファーから任意のファイルディスクリプターや、その逆方向、 もしくはあるバッファーから別のバッファーへの、データ移動を行う。 .TP \fBtee\fP(2) あるバッファーから別のバッファーへのデータ「コピー」を行う。 .TP \fBvmsplice\fP(2) ユーザー空間からバッファーへのデータ「コピー」を行う。 .PP .\" .\" Linus: Now, imagine using the above in a media server, for example. .\" Let's say that a year or two has passed, so that the video drivers .\" have been updated to be able to do the splice thing, and what can .\" you do? You can: .\" .\" - splice from the (mpeg or whatever - let's just assume that the video .\" input is either digital or does the encoding on its own - like they .\" pretty much all do) video input into a pipe (remember: no copies - the .\" video input will just DMA directly into memory, and splice will just .\" set up the pages in the pipe buffer) .\" - tee that pipe to split it up .\" - splice one end to a file (ie "save the compressed stream to disk") .\" - splice the other end to a real-time video decoder window for your .\" real-time viewing pleasure. .\" .\" Linus: Now, the advantage of splice()/tee() is that you can .\" do zero-copy movement of data, and unlike sendfile() you can .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more .\" than just sending the data to somebody else: you can duplicate .\" the data and choose to forward it to two or more different .\" users - for things like logging etc.). .\" ここではコピーの話をしているが、実際のコピーは一般的に回避される。 カーネルは、パイプバッファーをカーネルメモリーのページへのポインター集合として 実装し、ページへの参照回数を管理することで、これを実現している。 カーネルは、対象となるページを参照する (出力バッファー用の) ポインターを 新規に作成することでバッファー内のページの「コピー」を作成し、 そのページの参照回数を増やす。つまり、ポインターだけがコピーされ、 バッファーのページはコピーされない。 .SH 例 \fBtee\fP(2) 参照。 .SH 関連項目 \fBsendfile\fP(2), \fBtee\fP(2), \fBvmsplice\fP(2) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。