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