]>
Commit | Line | Data |
---|---|---|
2bc4bb77 MK |
1 | .\" Hey Emacs! This file is -*- nroff -*- source. |
2 | .\" | |
3 | .\" This manpage is Copyright (C) 2006 Jens Axboe | |
c11b1abf | 4 | .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com> |
2bc4bb77 MK |
5 | .\" |
6 | .\" Permission is granted to make and distribute verbatim copies of this | |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
2bc4bb77 MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
2bc4bb77 MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
25 | .\" | |
d9343c5c | 26 | .TH SPLICE 2 2006-04-28 "Linux" "Linux Programmer's Manual" |
2bc4bb77 MK |
27 | .SH NAME |
28 | splice \- splice data to/from a pipe | |
29 | .SH SYNOPSIS | |
30 | .nf | |
31 | .B #define _GNU_SOURCE | |
32 | .B #include <fcntl.h> | |
33 | ||
c13182ef | 34 | .BI "long splice(int " fd_in ", off_t *" off_in ", int " fd_out , |
2bc4bb77 MK |
35 | .BI " off_t *" off_out ", size_t " len \ |
36 | ", unsigned int " flags ); | |
37 | .fi | |
38 | .SH DESCRIPTION | |
39 | .BR splice () | |
c13182ef | 40 | moves data between two file descriptors |
2bc4bb77 MK |
41 | without copying between kernel address space and user address space. |
42 | It transfers up to | |
43 | .I len | |
44 | bytes of data from the file descriptor | |
45 | .I fd_in | |
46 | to the file descriptor | |
47 | .IR fd_out , | |
c13182ef | 48 | where one of the descriptors must refer to a pipe. |
2bc4bb77 MK |
49 | |
50 | If | |
ae39cf8f | 51 | .I fd_in |
2bc4bb77 | 52 | refers to a pipe, then |
c13182ef | 53 | .I off_in |
2bc4bb77 MK |
54 | must be NULL. |
55 | If | |
c13182ef | 56 | .I fd_in |
2bc4bb77 | 57 | does not refer to a pipe and |
ae39cf8f | 58 | .I off_in |
c13182ef | 59 | is NULL, then bytes are read from |
ae39cf8f | 60 | .I fd_in |
2bc4bb77 MK |
61 | starting from the current file offset, |
62 | and the current file offset is adjusted appropriately. | |
63 | If | |
c13182ef | 64 | .I fd_in |
2bc4bb77 | 65 | does not refer to a pipe and |
ae39cf8f | 66 | .I off_in |
c13182ef | 67 | is not NULL, then |
ae39cf8f | 68 | .I off_in |
2bc4bb77 MK |
69 | must point to a buffer which specifies the starting |
70 | offset from which bytes will be read from | |
ae39cf8f | 71 | .IR fd_in ; |
2bc4bb77 | 72 | in this case, the current file offset of |
0daa9e92 | 73 | .I fd_in |
2bc4bb77 MK |
74 | is not changed. |
75 | Analogous statements apply for | |
e267688b | 76 | .I fd_out |
2bc4bb77 | 77 | and |
ae39cf8f | 78 | .IR off_out . |
2bc4bb77 MK |
79 | |
80 | The | |
81 | .I flags | |
82 | argument is a bit mask that is composed by ORing together | |
83 | zero or more of the following values: | |
84 | .TP 1.9i | |
85 | .B SPLICE_F_MOVE | |
c13182ef | 86 | Attempt to move pages instead of copying. |
2bc4bb77 | 87 | This is only a hint to the kernel: |
c13182ef | 88 | pages may still be copied if the kernel cannot move the |
2bc4bb77 MK |
89 | pages from the pipe, or if |
90 | the pipe buffers don't refer to full pages. | |
91 | .TP | |
92 | .B SPLICE_F_NONBLOCK | |
93 | Do not block on I/O. | |
c13182ef | 94 | This makes the splice pipe operations non-blocking, but |
2bc4bb77 MK |
95 | .BR splice () |
96 | may nevertheless block because the file descriptors that | |
97 | are spliced to/from may block (unless they have the | |
0daa9e92 | 98 | .B O_NONBLOCK |
2bc4bb77 MK |
99 | flag set). |
100 | .TP | |
101 | .B SPLICE_F_MORE | |
102 | More data will be coming in a subsequent splice. | |
103 | This is a helpful hint when | |
c13182ef | 104 | the |
2bc4bb77 MK |
105 | .I fd_out |
106 | refers to a socket (see also the description of | |
107 | .B MSG_MORE | |
108 | in | |
109 | .BR send (2), | |
110 | and the description of | |
111 | .B TCP_CORK | |
112 | in | |
113 | .BR tcp (7)) | |
114 | .TP | |
115 | .B SPLICE_F_GIFT | |
116 | Unused for | |
117 | .BR splice (); | |
118 | see | |
119 | .BR vmsplice (2). | |
120 | .SH RETURN VALUE | |
121 | Upon successful completion, | |
122 | .BR splice () | |
123 | returns the number of bytes | |
c13182ef MK |
124 | spliced to or from the pipe. |
125 | A return value of 0 means that there was no data to transfer, | |
126 | and it would not make sense to block, because there are no | |
127 | writers connected to the write end of the pipe referred to by | |
2bc4bb77 MK |
128 | .IR fd_in . |
129 | ||
c13182ef | 130 | On error, |
2bc4bb77 MK |
131 | .BR splice () |
132 | returns \-1 and | |
133 | .I errno | |
134 | is set to indicate the error. | |
135 | .SH ERRORS | |
136 | .TP | |
137 | .B EBADF | |
c13182ef | 138 | One or both file descriptors are not valid, |
2bc4bb77 MK |
139 | or do not have proper read-write mode. |
140 | .TP | |
141 | .B EINVAL | |
142 | Target file system doesn't support splicing; | |
c13182ef | 143 | neither of the descriptors refers to a pipe; or |
2bc4bb77 MK |
144 | offset given for non-seekable device. |
145 | .TP | |
146 | .B ENOMEM | |
147 | Out of memory. | |
148 | .TP | |
149 | .B ESPIPE | |
c13182ef | 150 | Either |
2bc4bb77 | 151 | .I off_in |
c13182ef | 152 | or |
2bc4bb77 MK |
153 | .I off_out |
154 | was not NULL, but the corresponding file descriptor refers to a pipe. | |
ff457ccb | 155 | .SH VERSIONS |
2bc4bb77 MK |
156 | The |
157 | .BR splice (2) | |
7f3db312 | 158 | system call first appeared in Linux 2.6.17. |
2dd578fd MK |
159 | .SH "CONFORMING TO" |
160 | This system call is Linux specific. | |
2bc4bb77 MK |
161 | .SH NOTES |
162 | The three system calls | |
163 | .BR splice (2), | |
164 | .BR vmsplice (2), | |
165 | and | |
e267688b | 166 | .BR tee (2), |
c13182ef | 167 | provide userspace programs with full control over an arbitrary |
2bc4bb77 | 168 | kernel buffer, implemented within the kernel using the same type |
c13182ef | 169 | of buffer that is used for a pipe. |
2bc4bb77 MK |
170 | In overview, these system calls perform the following tasks: |
171 | .TP 1.2i | |
172 | .BR splice () | |
173 | moves data from the buffer to an arbitrary file descriptor, or vice versa, | |
174 | or from one buffer to another. | |
175 | .TP | |
0bfa087b | 176 | .BR tee (2) |
2bc4bb77 MK |
177 | "copies" the data from one buffer to another. |
178 | .TP | |
0bfa087b | 179 | .BR vmsplice (2) |
2bc4bb77 MK |
180 | "copies" data from user space into the buffer. |
181 | .PP | |
182 | Though we talk of copying, actual copies are generally avoided. | |
c13182ef | 183 | The kernel does this by implementing a pipe buffer as a set |
2bc4bb77 | 184 | of reference-counted pointers to pages of kernel memory. |
c13182ef MK |
185 | The kernel creates "copies" of pages in a buffer by creating new |
186 | pointers (for the output buffer) referring to the pages, | |
187 | and increasing the reference counts for the pages: | |
2bc4bb77 MK |
188 | only pointers are copied, not the pages of the buffer. |
189 | .\" | |
c13182ef MK |
190 | .\" Linus: Now, imagine using the above in a media server, for example. |
191 | .\" Let's say that a year or two has passed, so that the video drivers | |
192 | .\" have been updated to be able to do the splice thing, and what can | |
2bc4bb77 | 193 | .\" you do? You can: |
c13182ef | 194 | .\" |
2bc4bb77 MK |
195 | .\" - splice from the (mpeg or whatever - let's just assume that the video |
196 | .\" input is either digital or does the encoding on its own - like they | |
197 | .\" pretty much all do) video input into a pipe (remember: no copies - the | |
c13182ef | 198 | .\" video input will just DMA directly into memory, and splice will just |
2bc4bb77 MK |
199 | .\" set up the pages in the pipe buffer) |
200 | .\" - tee that pipe to split it up | |
201 | .\" - splice one end to a file (ie "save the compressed stream to disk") | |
c13182ef | 202 | .\" - splice the other end to a real-time video decoder window for your |
2bc4bb77 MK |
203 | .\" real-time viewing pleasure. |
204 | .\" | |
c13182ef MK |
205 | .\" Linus: Now, the advantage of splice()/tee() is that you can |
206 | .\" do zero-copy movement of data, and unlike sendfile() you can | |
207 | .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more | |
208 | .\" than just sending the data to somebody else: you can duplicate | |
209 | .\" the data and choose to forward it to two or more different | |
2bc4bb77 MK |
210 | .\" users - for things like logging etc). |
211 | .\" | |
212 | .SH EXAMPLE | |
213 | See | |
214 | .BR tee (2). | |
2bc4bb77 MK |
215 | .SH SEE ALSO |
216 | .BR sendfile (2), | |
217 | .BR splice (2), | |
0a90178c MK |
218 | .BR tee (2), |
219 | .BR feature_test_macros (7) |