1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
.\" 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 $
.TH SENDFILE 2 "1 Dec 1998" "Linux Man Page" "Linux Programmer's Manual"
.SH NAME
sendfile \- transfer data between file descriptors
.SH SYNOPSIS
.B #include <unistd.h>
.sp
.BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" offset ", size_t" " count" )
.\" The below is too ugly. Comments about glibc versions belong
.\" in the notes, not in the header.
.\" Moreover, all system calls should be defined in <unistd.h>.
.\"
.\" .B #include <features.h>
.\" .br
.\" .B #if (__GLIBC__==2 && __GLIBC_MINOR__>=1) || __GLIBC__>2
.\" .br
.\" .B #include <sys/sendfile.h>
.\" .br
.\" #else
.\" .br
.\" .B #include <sys/types.h>
.\" .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 DESCRIPTION
This call copies data between one file descriptor and another.
Either or both of these file descriptors may refer to a socket.
.I in_fd
should be a file descriptor opened for reading and
.I out_fd
should be a descriptor opened for writing.
.I offset
is a pointer to a variable holding the input file pointer position from
which
.BR sendfile (2)
will start reading data. When
.B sendfile
returns, this variable
will be set to the offset of the byte following the last byte that was read.
.I count
is the number of bytes to copy between file descriptors.
.SH NOTES
Sendfile does not modify the current file pointer of
.IR in_fd ,
but does for
.IR 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
.B TCP_CORK
option in
.BR tcp (7)
to minimize the number of packets and to tune performance.
.SH "RETURN VALUE"
If the transfer was successful, the number of bytes written to
.I out_fd
is returned. On error, \-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EBADF
The input file was not opened for reading or the output file was not opened for writing.
.TP
.B EINVAL
Descriptor is not valid or locked.
.\" These two are from do_generic_file_read() in filemap.c
.TP
.B ENOMEM
Insufficient memory to read from
.IR in_fd .
.TP
.B EIO
Unspecified error while reading from
.IR in_fd .
.SH VERSIONS
.B sendfile
is a new feature in Linux 2.2.
Other Unixes often implement
.B sendfile
with different semantics and prototypes. It should
not be used in portable programs.
.SH SEE ALSO
.BR socket (2),
.BR open (2)
|