'\" te .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .\" Copyright 2022 Garrett D'Amore .TH SENDFILEV 3EXT "July 3, 2022" .SH NAME sendfilev \- send a file .SH SYNOPSIS .nf \fBcc\fR [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lsendfile\fR [ \fIlibrary\fR... ] #include \fBssize_t\fR \fBsendfilev\fR(\fBint\fR \fIfildes\fR, \fBconst struct sendfilevec *\fR\fIvec\fR, \fBint\fR \fIsfvcnt\fR, \fBsize_t *\fR\fIxferred\fR); .fi .SH PARAMETERS The \fBsendfilev()\fR function supports the following parameters: .sp .ne 2 .na \fB\fIfildes\fR\fR .ad .RS 11n A file descriptor to a regular file or to a \fBAF_INET\fR or \fBAF_INET6\fR family type \fBSOCK_STREAM\fR socket that is open for writing. .RE .sp .ne 2 .na \fB\fIvec\fR\fR .ad .RS 11n An array of \fBSENDFILEVEC_T\fR, as defined in the \fBsendfilevec\fR structure below. .RE .sp .ne 2 .na \fB\fIsfvcnt\fR\fR .ad .RS 11n The number of members in \fIvec\fR. .RE .sp .ne 2 .na \fB\fIxferred\fR\fR .ad .RS 11n The total number of bytes written to \fBout_fd\fR. .RE .SH DESCRIPTION The \fBsendfilev()\fR function attempts to write data from the \fIsfvcnt\fR buffers specified by the members of \fIvec\fR array: \fBvec[0], vec[1], ... , vec[sfvcnt-1]\fR. The \fIfildes\fR argument is a file descriptor to a regular file or to an \fBAF_INET\fR or \fBAF_INET6\fR family type \fBSOCK_STREAM\fR socket that is open for writing. .sp .LP This function is analogous to \fBwritev\fR(2), but can read from both buffers and file descriptors. Unlike \fBwritev()\fR, in the case of multiple writers to a file the effect of \fBsendfilev()\fR is not necessarily atomic; the writes may be interleaved. Application-specific synchronization methods must be employed if this causes problems. .sp .LP The following is the \fBsendfilevec\fR structure: .sp .in +2 .nf typedef struct sendfilevec { int sfv_fd; /* input fd */ uint_t sfv_flag; /* Flags. see below */ off_t sfv_off; /* offset to start reading from */ size_t sfv_len; /* amount of data */ } sendfilevec_t; #define SFV_FD_SELF (-2) .fi .in -2 .sp .LP To send a file, open the file for reading and point \fBsfv_fd\fR to the file descriptor returned as a result. See \fBopen\fR(2). \fBsfv_off\fR should contain the offset within the file. \fBsfv_len\fR should have the length of the file to be transferred. .sp .LP The \fIxferred\fR argument is updated to record the total number of bytes written to \fBout_fd\fR. .sp .LP The \fBsfv_flag\fR field is reserved and should be set to zero. .sp .LP To send data directly from the address space of the process, set \fBsfv_fd\fR to \fBSFV_FD_SELF\fR. \fBsfv_off\fR should point to the data, with \fBsfv_len\fR containing the length of the buffer. .SH RETURN VALUES Upon successful completion, the \fBsendfilev()\fR function returns total number of bytes written to \fBout_fd\fR. Otherwise, it returns \fB-1\fR, and \fBerrno\fR is set to indicate the error. The \fIxferred\fR argument contains the amount of data successfully transferred, which can be used to discover the error vector. .SH ERRORS .ne 2 .na \fB\fBEACCES\fR\fR .ad .RS 16n The process does not have appropriate privileges or one of the files pointed by \fBsfv_fd\fR does not have appropriate permissions. .RE .sp .ne 2 .na \fB\fBEAFNOSUPPORT\fR\fR .ad .RS 16n The implementation does not support the specified address family for socket. .RE .sp .ne 2 .na \fB\fBEAGAIN\fR\fR .ad .RS 16n Mandatory file or record locking is set on either the file descriptor or output file descriptor if it points at regular files. \fBO_NDELAY\fR or \fBO_NONBLOCK\fR is set, and there is a blocking record lock. An attempt has been made to write to a stream that cannot accept data with the \fBO_NDELAY\fR or the \fBO_NONBLOCK\fR flag set. .RE .sp .ne 2 .na \fB\fBEBADF\fR\fR .ad .RS 16n The \fIfildes\fR argument is not a valid descriptor open for writing or an \fBsfv_fd\fR is invalid or not open for reading. .RE .sp .ne 2 .na \fB\fBEFAULT\fR\fR .ad .RS 16n The \fIvec\fR argument points to an illegal address. .sp The \fIxferred\fR argument points to an illegal address. .RE .sp .ne 2 .na \fB\fBEINTR\fR\fR .ad .RS 16n A signal was caught during the write operation and no data was transferred. .RE .sp .ne 2 .na \fB\fBEINVAL\fR\fR .ad .RS 16n The \fIsfvcnt\fR argument was less than or equal to \fB0\fR. One of the \fBsfv_len\fR values in \fIvec\fR array was less than or equal to \fB0\fR, or greater than the file size. An \fBsfv_fd\fR is not seekable. .sp Fewer bytes were transferred than were requested. .RE .sp .ne 2 .na \fB\fBEIO\fR\fR .ad .RS 16n An I/O error occurred while accessing the file system. .RE .sp .ne 2 .na \fB\fBEPIPE\fR\fR .ad .RS 16n The \fIfildes\fR argument is a socket that has been shut down for writing. The \fBSIGPIPE\fR signal is generated to the calling thread. The process dies unless special provisions were taken to catch or ignore the signal. .RE .sp .ne 2 .na \fB\fBEPROTOTYPE\fR\fR .ad .RS 16n The socket type is not supported. .RE .SH USAGE The \fBsendfilev()\fR function has a transitional interface for 64-bit file offsets. See \fBlf64\fR(7). .SH EXAMPLES The following example sends 2 vectors, one of HEADER data and a file of length 100 over \fBsockfd\fR. \fBsockfd\fR is in a connected state, that is, \fBsocket()\fR, \fBaccept()\fR, and \fBbind()\fR operation are complete. .sp .in +2 .nf #include \&. \&. \&. int main (int argc, char *argv[]){ int sockfd; ssize_t ret; size_t xfer; struct sendfilevec vec[2]; . . . vec[0].sfv_fd = SFV_FD_SELF; vec[0].sfv_flag = 0; vec[0].sfv_off = "HEADER_DATA"; vec[0].sfv_len = strlen("HEADER_DATA"); vec[1].sfv_fd = open("input_file",.... ); vec[1].sfv_flag = 0; vec[1].sfv_off = 0; vec[1].sfv_len = 100; ret = sendfilev(sockfd, vec, 2, &xfer); \&. \&. \&. } .fi .in -2 .SH ATTRIBUTES See \fBattributes\fR(7) for descriptions of the following attributes: .sp .sp .TS box; c | c l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed _ MT-Level MT-Safe .TE .SH SEE ALSO .BR open (2), .BR writev (2), .BR sendfile (3EXT), .BR libsendfile (3LIB), .BR socket (3SOCKET), .BR attributes (7)