sendfile(2) System Calls Manual sendfile(2) sendfile - LIBRARY Standard C library (libc, -lc) #include ssize_t sendfile(int out_fd, int in_fd, off_t *_Nullable offset, size_t count); sendfile() . , sendfile() read(2) write(2), . in_fd , , out_fd , . offset NULL, , sendfile() in_fd. sendfile() . offset NULL, sendfile() in_fd; in_fd . offset NULL, in_fd , . count , . The in_fd argument must correspond to a file which supports mmap(2)-like operations (i.e., it cannot be a socket). Except since Linux 5.12 and if out_fd is a pipe, in which case sendfile() desugars to a splice(2) and its restrictions apply. Before Linux 2.6.33, out_fd must refer to a socket. Since Linux 2.6.33 it can be any file. If it's seekable, then sendfile() changes the file offset appropriately. , out_fd . , sendfile() , ; , . . -1, errno . EAGAIN - O_NONBLOCK, . EBADF . EFAULT . EINVAL , in_fd mmap(2) count . EINVAL out_fd O_APPEND. sendfile(). EIO in_fd. ENOMEM in_fd. EOVERFLOW count , , . ESPIPE offset is not NULL but the input file is not seekable. UNIX sendfile() . . None. Linux 2.2, glibc 2.1. Linux 2.4 , out_fd ; Linux 2.6.x, 2.6.33. Linux sendfile() . Linux 2.4 sendfile64() offset. glibc sendfile() , . sendfile() 0x7ffff000 (2 147 479 552) , , ( 32-, 64- ). sendfile() TCP , TCP_CORK, tcp(7), . Applications may wish to fall back to read(2) and write(2) in the case where sendfile() fails with EINVAL or ENOSYS. out_fd , , , in_fd, , out_fd . Linux splice(2) , ( ). . copy_file_range(2), mmap(2), open(2), socket(2), splice(2) Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 21 2023 . sendfile(2)