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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
'\" 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]
.TH SENDFILEV 3EXT "Feb 25, 2009"
.SH NAME
sendfilev \- send a file
.SH SYNOPSIS
.LP
.nf
\fBcc\fR [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lsendfile\fR [ \fIlibrary\fR... ]
#include <sys/sendfile.h>
\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
.sp
.LP
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_NCA\fR, \fBAF_INET\fR, or
\fBAF_INET6\fR family type \fBSOCK_STREAM\fR socket that is open for writing.
For \fBAF_NCA\fR, the protocol type should be zero.
.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
above.
.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
.sp
.LP
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_NCA\fR, \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
.sp
.LP
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 successfuly transferred, which can be used to discover the
error vector.
.SH ERRORS
.sp
.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.
.RE
.sp
.ne 2
.na
\fB\fBEPROTOTYPE\fR\fR
.ad
.RS 16n
The socket type is not supported.
.RE
.SH USAGE
.sp
.LP
The \fBsendfilev()\fR function has a transitional interface for 64-bit file
offsets. See \fBlf64\fR(5).
.SH EXAMPLES
.sp
.LP
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 <sys/sendfile.h>
\&.
\&.
\&.
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
.sp
.LP
See \fBattributes\fR(5) 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
.sp
.LP
\fBopen\fR(2), \fBwritev\fR(2), \fBlibsendfile\fR(3LIB), \fBsendfile\fR(3EXT),
\fBsocket\fR(3SOCKET), \fBattributes\fR(5)
|