sendfile - Send the contents of a file through a socket
#include <sys/socket.h>
ssize_t sendfile(
int socket,
int fd,
off_t offset,
size_t nbytes,
const struct iovec *hdtrl,
int flags );
Specifies the socket file descriptor. Specifies the file
descriptor of the file that contains the contents to be
sent. Specifies the point within the file (offset) at
which to start the data transfer. Specifies the number of
bytes to send from the file. If the value is zero (0),
data from the offset to the end of the file is sent.
Points to a two-entry array of iovec structures. The first
entry contains header information. If the iov_len member
is non-zero, the contents of the buffer are sent before
any data from the file.
The second entry contains trailer information. If
the iov_len member is non-zero, the contents of the
buffer are sent after any data from the file.
If both iov_len members are NULL or if hdtrl is a
NULL pointer, only the specified file contents are
transferred.
See write(2) for information on the iovec structure.
Not currently used.
The sendfile() function sends the specified contents of a
file only through a connected socket.
Upon successful completion, the sendfile() function
returns the number of bytes sent, including the header,
trailer, and file contents. Otherwise, the function
returns a value of -1 and sets errno to indicate the
error.
If the sendfile() function fails, errno may be set to one
of the following values: Non-blocking I/O is enabled
(O_NONBLOCK), and the requested operation would block.
Addresses in the specified address family cannot be used
with this socket. The socket parameter or file descriptor
is not valid. The hdtrl parameter is not valid or there
is an invalid pointer in the iovec structure. A signal
interrupted sendfile before any data was transmitted. If
some data was transmitted, the function returns the number
of bytes sent before the interrupt and does not set errno
to [EINTR]. The offset or flags parameter is invalid.
The hdtrl parameter, or a length in the iovec
structure is invalid. There is insufficient space
in the socket buffer. The system did not have sufficient
memory to fulfill the request. A socket is
connection-oriented but is not connected, has not
completed the connect sequence with its peer, or is
no longer connected to its peer. The socket parameter
refers to a file, not a socket. The socket is
not a TCP socket. You attempted to send on a
socket that was connected, but either the remote
peer or localhost has closed the connection. If the
process does not have a signal handler for this
signal (SIGPIPE), the default action is to terminate
the process. The socket is marked nonblocking,
and the requested operation would block.
Functions: connect(2), read(2), send(2), shutdown(2),
socket(2), write(2), tcp(7).
sendfile(2)
[ Back ] |