Linux Standard Base Core Specification, Generic Part | ||
---|---|---|
<<< Previous | Next >>> |
The sendfile() function shall copy data between the file descriptor in_fd, which must not be a socket, and the file descriptor out_fd, which must be a socket. in_fd should be opened for reading, and out_fd should be opened for writing.
The offset parameter points to a variable set to the file offset at which sendfile() shall start reading from in_fd, unless it is NULL. On exit, this variable shall contain the offset of the byte immediately after the last byte read. sendfile() shall not change the current file offset of in_fd, unless it is NULL. In that case, sendfile() shall adjust the current file offset to show how many bytes were read.
The count parameter specifies how many bytes to copy.
On success, sendfile() shall return the number of bytes written to out_fd.
On failure, sendfile() shall return
-1 and set errno
appropriately, as follows.
sendfile() is usually faster than combining
read() and write() calls,
because it is part of the kernel.
However, if it fails with EINVAL
,
falling back to read() and write() may be advisable.
It is advisable for performance reasons to use the
TCP_CORK
option of the tcp() function
when sending header data with file contents to a TCP socket.
This minimizes the number of packets.
<<< Previous | Home | Next >>> |
seed48_r | Up | sendfile64 |