Seth Woolley's Man Viewer

Manual for sendfile - man 2 sendfile

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

SENDFILE(2)                Linux Programmer's Manual               SENDFILE(2)



NAME
       sendfile(1,2) - transfer data between file(1,n) descriptors

SYNOPSIS
       #include <sys/sendfile.h>

       ssize_t sendfile(1,2)(int out_fd, int in_fd, off_t *offset, size_t count);

DESCRIPTION
       This  call copies data between one file(1,n) descriptor and another.  Either
       or both of these file(1,n) descriptors  may  refer  to  a  socket(2,7,n)  (but  see
       below).   in_fd  should  be  a  file(1,n)  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(1,n) pointer position from which send-
       file(1,n)() will start reading data.  When sendfile(1,2)() returns, this variable
       will  be set(7,n,1 builtins) to the offset of the byte following the last byte that was
       read.  count is the number of bytes to copy between file(1,n) descriptors.

       Because this copying is done within the  kernel,  sendfile(1,2)()  does  not
       need to spend time(1,2,n) transferring data to and from user space.


NOTES
       Sendfile  does  not  modify the current file(1,n) pointer of in_fd, but does
       for out_fd.

       If you plan to use sendfile(1,2) for sending files to a TCP socket(2,7,n), but need
       to  send(2,n) some header data in(1,8) front of the file(1,n) contents, please see the
       TCP_CORK option in(1,8) tcp(7) to minimize the number of packets and to tune
       performance.

       Presently the descriptor from which data is read(2,n,1 builtins) cannot correspond to a
       socket(2,7,n), it must correspond to a file(1,n) which supports mmap()-like  opera-
       tions.


RETURN VALUE
       If  the  transfer was successful, the number of bytes written to out_fd
       is returned.  On error(8,n), -1 is returned, and errno is set(7,n,1 builtins) appropriately.


ERRORS
       EAGAIN Non-blocking  I/O  has  been  selected  using O_NONBLOCK and the
              write(1,2) would block.

       EBADF  The input file(1,n) was not opened for reading or the output file(1,n) was
              not opened for writing.

       EFAULT Bad address.

       EINVAL Descriptor is not valid or locked.

       EIO    Unspecified error(8,n) while reading from in_fd.

       ENOMEM Insufficient memory to read(2,n,1 builtins) from in_fd.

VERSIONS
       sendfile(1,2)  is  a  new feature in(1,8) Linux 2.2.  The include file(1,n) <sys/send-
       file.h> is present since glibc2.1.

       Other Unixes often implement sendfile(1,2) with different semantics and pro-
       totypes. It should not be used in(1,8) portable programs.

SEE ALSO
       open(2,3,n)(2), socket(2,7,n)(2)



Linux Man Page                    1998-12-01                       SENDFILE(2)

References for this manual (incoming links)