.\" This man page is Copyright (C) 1998 Pawel Krawczyk. .\" Permission is granted to distribute possibly modified copies .\" of this page provided the header is included verbatim, .\" and in case of nontrivial modification author and date .\" of the modification is added to the header. .\" $Id: sendfile.2,v 1.5 1999/05/18 11:54:11 freitag Exp $ .\" 2000-11-19 bert hubert : in_fd cannot be socket .\" .\" 2004-12-17, mtk .\" updated description of in_fd and out_fd for 2.6 .\" Various wording and formatting changes .\" .\" 2005-03-31 Martin Pool mmap() improvements .\" .\" Japanese Version Copyright (c) 1999 HANATAKA Shinya .\" all rights reserved. .\" Translated 1999-06-26, HANATAKA Shinya .\" Updated 2001-02-16, Kentaro Shirakata .\" Updated 2003-09-08, Kentaro Shirakata .\" Updated 2005-03-14, Akihiro MOTOKI .\" Updated 2005-04-17, Akihiro MOTOKI .\" Updated 2010-04-18, Akihiro MOTOKI , LDP v3.24 .\" .\"WORD: descriptor ディスクリプタ .\"WORD: socket ソケット .\"WORD: lock ロック .\" .TH SENDFILE 2 2010-02-15 "Linux" "Linux Programmer's Manual" .SH 名前 sendfile \- ファイル・ディスクリプタ間でデータを転送する .SH 書式 .B #include .sp .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \ offset ", size_t" " count" ); .\"O .\" The below is too ugly. Comments about glibc versions belong .\"O .\" in the notes, not in the header. .\" 以下は、あまりにも汚い。 glibc バージョンについてのコメントは .\" 「ヘッダ」ではなく、「注意」に書いておく。 .\" .\" .B #include .\" .br .\" .B #if (__GLIBC__==2 && __GLIBC_MINOR__>=1) || __GLIBC__>2 .\" .br .\" .B #include .\" .br .\" #else .\" .br .\" .B #include .\" .br .\" .B /* No system prototype before glibc 2.1. */ .\" .br .\" .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \ .\" offset ", size_t" " count" ) .\" .br .\" .B #endif .\" .SH 説明 .\"O .BR sendfile () .\"O copies data between one file descriptor and another. .\"O Because this copying is done within the kernel, .\"O .BR sendfile () .\"O is more efficient than the combination of .\"O .BR read (2) .\"O and .\"O .BR write (2), .\"O which would require transferring data to and from user space. .BR sendfile () は、あるファイル・ディスクリプタから別の ファイル・ディスクリプタへのデータのコピーを行う。 このコピーはカーネル内で行われるので、 .BR sendfile () は、 .BR read (2) と .BR write (2) を組み合わせるよりも効率がよい。 .BR read (2) や .BR write (2) ではユーザ空間との間でデータの転送が必要となるからである。 .\"O .I in_fd .\"O should be a file descriptor opened for reading and .\"O .I out_fd .\"O should be a descriptor opened for writing. .I in_fd は読み込みのためにオープンされたファイル・ディスクリプタ、 .I out_fd は書き込みのためにオープンされたディスクリプタでなければならない。 .\"O If .\"O .I offset .\"O is not NULL, then it points .\"O to a variable holding the file offset from which .\"O .BR sendfile () .\"O will start reading data from .\"O .IR in_fd . .\"O When .\"O .BR sendfile () .\"O returns, this variable .\"O will be set to the offset of the byte following the last byte that was read. .I offset が NULL でない場合、 .I offset は .BR sendfile () が .I in_fd のどこからデータを読み始めるかを示すファイル・オフセットを保持する変数への ポインタである。 .BR sendfile () は復帰する時、この変数に最後に読み込んだバイトの 次のバイトのオフセットを書き込む。 .\"O If .\"O .I offset .\"O is not NULL, then .\"O .BR sendfile () .\"O does not modify the current file offset of .\"O .IR in_fd ; .\"O otherwise the current file offset is adjusted to reflect .\"O the number of bytes read from .\"O .IR in_fd . .I offset が NULL でない場合、 .BR sendfile () は .I in_fd のファイル・オフセットの現在値を変更しない。 NULL の場合は、ファイル・オフセットの現在値を .I in_fd から読み込んだバイト数を反映した位置に調整する。 .\"O If .\"O .I offset .\"O is NULL, then data will be read from .\"O .IR in_fd .\"O starting at the current file offset, .\"O and the file offset will be updated by the call. .I offset が NULL の場合、データは .I in_fd の現在のファイル・オフセットから読み出され、 ファイル・オフセットはこの呼び出しで更新される。 .\"O .I count .\"O is the number of bytes to copy between the file descriptors. .I count は、ファイル・ディスクリプタ間でコピーするバイト数である。 .\"O Presently (Linux 2.6.9): .\"O .IR in_fd , .\"O must correspond to a file which supports .\"O .BR mmap (2)-like .\"O operations .\"O (i.e., it cannot be a socket); .\"O and .\"O .I out_fd .\"O must refer to a socket. 今のところ (Linux 2.6.9 では)、 .I in_fd は .BR mmap (2) 風の操作ができるファイルを指していなければならない (ソケットを指してはならない)。また、 .I out_fd はソケットを指していなければならない。 .\"O Applications may wish to fall back to .\"O .BR read (2)/ write (2) .\"O in the case where .\"O .BR sendfile () .\"O fails with .\"O .B EINVAL .\"O or .\"O .BR ENOSYS . .BR sendfile () が .B EINVAL や .B ENOSYS で失敗するような場合は、 アプリケーションは .BR read (2)/ write (2) に戻すことを考えてもよいかもしれない。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O If the transfer was successful, the number of bytes written to .\"O .I out_fd .\"O is returned. .\"O On error, \-1 is returned, and .\"O .I errno .\"O is set appropriately. 転送に成功した場合、 .I out_fd に書き込まれたバイト数を返す。エラーの場合、\-1 を返し、 .I errno に適切な値を設定する。 .\"O .SH ERRORS .SH エラー .TP .B EAGAIN .\"O Nonblocking I/O has been selected using .\"O .B O_NONBLOCK .\"O and the write would block. .B O_NONBLOCK を用いて非ブロック I/O が選択されたが、書き込みがブロックされた。 .TP .B EBADF .\"O The input file was not opened for reading or the output file .\"O was not opened for writing. 入力ファイルが読み込みのためにオープンされていないか、 出力ファイルが書き込みのためにオープンされていない。 .TP .B EFAULT .\"O Bad address. アドレスがおかしい。 .TP .B EINVAL .\"O Descriptor is not valid or locked, or an .\"O .BR mmap (2)-like .\"O operation is not available for .\"O .IR in_fd . ディスクリプタが有効でないか、ロックされている。もしくは .BR mmap (2) 風の操作が .I in_fd では利用できない。 .TP .B EIO .\"O Unspecified error while reading from .\"O .IR in_fd . .I in_fd から読み込んでいるうちに予期しないエラーが起こった。 .TP .B ENOMEM .\"O Insufficient memory to read from .\"O .IR in_fd . .I in_fd から読み込むための十分なメモリがない。 .\"O .SH VERSIONS .SH バージョン .\"O .B sendfile .\"O is a new feature in Linux 2.2. .B sendfile は Linux 2.2 の新しい機能である。 .\"O The include file .\"O .I .\"O is present since glibc 2.1. インクルードファイル .I は glibc 2.1 から存在している。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O Not specified in POSIX.1-2001, or other standards. POSIX.1-2001 や他の標準では規定されていない。 .\"O Other UNIX systems implement .\"O .BR sendfile () .\"O with different semantics and prototypes. .\"O It should not be used in portable programs. 他の UNIX システムでは、異なった方式やプロトタイプで .BR sendfile () を実装している。移植性を考慮したプログラムでは使用すべきではない。 .\"O .SH NOTES .SH 注意 .\"O If you plan to use .\"O .BR sendfile () .\"O for sending files to a TCP socket, but need .\"O to send some header data in front of the file contents, you will find .\"O it useful to employ the .\"O .B TCP_CORK .\"O option, described in .\"O .BR tcp (7), .\"O to minimize the number of packets and to tune performance. .BR sendfile () を使って TCP ソケットにファイルを送ろうとしていて、 ファイルの内容の前にヘッダ・データを付け加える必要がある場合は、 パケット数を最小にして性能を上げるために .BR tcp (7) に記述されている .B TCP_CORK オプションを使うといいだろう。 .\"O In Linux 2.4 and earlier, .\"O .I out_fd .\"O could refer to a regular file, and .\"O .BR sendfile () .\"O changed the current offset of that file. Linux 2.4 とそれ以前のバージョンでは、 .I out_fd は通常のファイルを参照でき、 .BR sendfile () はそのファイルのオフセットの現在値を変更していた。 .\"O .SH SEE ALSO .SH 関連項目 .BR mmap (2), .BR open (2), .BR socket (2), .BR splice (2)