-> Click here to learn how to get live help <-
NAMEsendfile - transfer data between file descriptors
DESCRIPTIONThis call copies data between one file descriptor and another. Either or both of these file descriptors may refer to a socket (but see below). in_fd should be a file descriptor opened for reading and out_fd should be a descriptor opened for writing. offset is a pointer to a variable holding the input file pointer position from which sendfile() will start reading data. When sendfile() returns, this variable will be set to the offset of the byte following the last byte that was read. count is the number of bytes to copy between file descriptors.
Because this copying is done within the kernel, sendfile() does not need to spend time transferring data to and from user space.
NOTESSendfile does not modify the current file pointer of in_fd, but does for out_fd.
If you plan to use sendfile for sending files to a TCP socket, but need to send some header data in front of the file contents, please see the TCP_CORK option in tcp(7) to minimize the number of packets and to tune performance.
Presently the descriptor from which data is read cannot correspond to a socket, it must correspond to a file which supports mmap()-like operations.
RETURN VALUEIf the transfer was successful, the number of bytes written to out_fd is returned. On error, -1 is returned, and errno is set appropriately.
VERSIONSsendfile is a new feature in Linux 2.2. The include file <sys/sendfile.h> is present since glibc2.1.
SEE ALSOsocket(2), open(2)