Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > S


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


sendfile64() — send the contents of a Large File through a socket


#include <sys/socket.h>

sbsize64_t sendfile64(int s, int fd, off64_t offset, bsize64_t nbytes, const struct iovec *hdtrl, int flags);


The sendfile64() system call transmits the contents of a file (including a Large File (greater than 2GB)) associated with the file descriptor fd, plus an optional header and trailer buffers across a socket connection specified by s. sendfile64() should be used by 32-bit applications using Large Files; however, 64-bit applications can use sendfile64() for compatibility. 64-bit applications can also use sendfile() directly to send Large Files without special compile flags. sendfile64() can be used only when the socket is in a connected state.

offset specifies the offset within the file at which to start the file data transfer.

nbytes is the number of bytes to be sent from the file. If this parameter is set to zero, data from the offset to the end of the file will be sent.

hdtrl points to a two entry iovec structure. See write(2) for a description of the iovec structure. The first entry is for header information. If this pointer is non-NULL, the contents of the buffer are sent before sending any data from the file. The second entry is for trailer information. If this pointer is non-NULL, the contents of the buffer will be sent after the data from the file. If both pointers are NULL, or hdtrl is a NULL pointer, only the specified range of the file will be transferred.

At the end of the call, the socket connection will be left completely open for both reading and writing, unless the flags parameter is set to:


Disallow further sends and receives.


If no buffer space is available to hold the data to be transmitted, sendfile64() blocks unless nonblocking mode is enabled. See send(2) for a description of the nonblocking mode behavior.

Applications that compile with the _FILE_OFFSET_BITS=64 compile flag have sendfile() system calls converted implicitly to sendfile64(). Also bsize_t, sbsize_t, and off_t types are implicitly converted to bsize64_t, sbsize64_t, and off64_t types.

Both the _LARGEFILE64_SOURCE and _FILE_OFFSET_BITS=64 compile flag must be used to explicitly use the sendfile64() system call. These are the recommended compile flags for both applications using either sendfile() or sendfile64() that may want to access Large Files.


Upon successful completion, sendfile64() returns the number of bytes sent. This includes the header, trailer, and the file contents. Otherwise, -1 is returned and errno is set to indicate the error.


If sendfile64() fails, errno is set to one of the following values.


An invalid socket descriptor s , or file descriptor fd is specified.


s is a valid file descriptor, but it is not a socket.


An invalid pointer was specified in the hdtrl parameter or the iovec structure.


No buffer space is available in the system to perform the operation.


The operation was interrupted by a signal before any data was sent. (If some data was sent, sendfile64() returns the number of bytes sent before the signal, and EINTR is not set.)


The offset or flags parameter is invalid.

The hdtrl parameter, or a length in the iovec structure is invalid.


A sendfile64() on a socket that is not connected, or a sendfile64() on a socket that has not completed the connect sequence with its peer, or is no longer connected to its peer.


With SIGPIPE signal. An attempt was made to send on a socket that was connected, but the connection has been shut down either by the remote peer or by this side of the connection. Note that the default action for SIGPIPE, unless the process has established a signal handler for this signal, is to terminate the process.


Nonblocking I/O is enabled using the O_NONBLOCK flag with fcntl(), and the requested operation would block.


The socket is marked nonblocking and the requested operation would block.


No memory is available in the system to perform the operation.


The socket is not a TCP socket.


An application has opened a large file (see open(2)) and is trying to use sendfile64 without having been compiled with _LARGEFILE64_SOURCE and _FILE_OFFSET_BITS=64 compile flags.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.