Index Index for
Section 2
Index Alphabetical
listing for S
Bottom of page Bottom of
page

sendfile(2)

NAME

sendfile - Send the contents of a file through a socket

SYNOPSIS

#include <sys/socket.h> ssize_t sendfile( int socket, int fd, off_t offset, size_t nbytes, const struct iovec *hdtrl, int flags );

PARAMETERS

socket Specifies the socket file descriptor. fd Specifies the file descriptor of the file that contains the contents to be sent. offset Specifies the point within the file (offset) at which to start the data transfer. nbytes 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. hdtrl 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. flags Not currently used.

DESCRIPTION

The sendfile() function sends the specified contents of a file only through a connected socket.

RETURN VALUES

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.

ERRORS

If the sendfile() function fails, errno may be set to one of the following values: [EAGAIN] Non-blocking I/O is enabled (O_NONBLOCK), and the requested operation would block. [EAFNOSUPPORT] Addresses in the specified address family cannot be used with this socket. [EBADF] The socket parameter or file descriptor is not valid. [EFAULT] The hdtrl parameter is not valid or there is an invalid pointer in the iovec structure. [EINTR] 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]. [EINVAL] The offset or flags parameter is invalid. The hdtrl parameter, or a length in the iovec structure is invalid. [EMSGSIZE] There is insufficient space in the socket buffer. [ENOMEM] The system did not have sufficient memory to fulfill the request. [ENOTCONN] 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. [ENOTSOCK] The socket parameter refers to a file, not a socket. [EOPNOTSUPP] The socket is not a TCP socket. [EPIPE] 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. [EWOULDBLOCK] The socket is marked nonblocking, and the requested operation would block.

SEE ALSO

Functions: connect(2), read(2), send(2), shutdown(2), socket(2), write(2), tcp(7).

Index Index for
Section 2
Index Alphabetical
listing for S
Top of page Top of
page