1SPLICE(2)                  Linux Programmer's Manual                 SPLICE(2)
2
3
4

NAME

6       splice - splice data to/from a pipe
7

SYNOPSIS

9       #define _GNU_SOURCE         /* See feature_test_macros(7) */
10       #include <fcntl.h>
11
12       ssize_t splice(int fd_in, loff_t *off_in, int fd_out,
13                      loff_t *off_out, size_t len, unsigned int flags);
14

DESCRIPTION

16       splice()  moves  data  between  two  file  descriptors  without copying
17       between kernel address space and user address space.  It  transfers  up
18       to  len  bytes  of  data  from  the  file  descriptor fd_in to the file
19       descriptor fd_out, where one of the descriptors must refer to a pipe.
20
21       If fd_in refers to a pipe, then off_in must be NULL.  If fd_in does not
22       refer  to  a  pipe  and  off_in is NULL, then bytes are read from fd_in
23       starting from the current file offset, and the current file  offset  is
24       adjusted  appropriately.   If fd_in does not refer to a pipe and off_in
25       is not NULL, then off_in must point to a  buffer  which  specifies  the
26       starting offset from which bytes will be read from fd_in; in this case,
27       the current file offset of fd_in is not changed.  Analogous  statements
28       apply for fd_out and off_out.
29
30       The  flags  argument  is  a bit mask that is composed by ORing together
31       zero or more of the following values:
32
33       SPLICE_F_MOVE      Attempt to move pages instead of copying.   This  is
34                          only a hint to the kernel: pages may still be copied
35                          if the kernel cannot move the pages from  the  pipe,
36                          or  if  the  pipe buffers don't refer to full pages.
37                          The initial implementation of this flag  was  buggy:
38                          therefore  starting  in  Linux  2.6.21 it is a no-op
39                          (but is still permitted in a splice() call); in  the
40                          future, a correct implementation may be restored.
41
42       SPLICE_F_NONBLOCK  Do  not  block  on  I/O.  This makes the splice pipe
43                          operations nonblocking, but splice()  may  neverthe‐
44                          less  block  because  the  file descriptors that are
45                          spliced to/from may  block  (unless  they  have  the
46                          O_NONBLOCK flag set).
47
48       SPLICE_F_MORE      More  data  will  be  coming in a subsequent splice.
49                          This is a helpful hint when the fd_out refers  to  a
50                          socket  (see  also  the  description  of MSG_MORE in
51                          send(2), and the description of TCP_CORK in tcp(7))
52
53       SPLICE_F_GIFT      Unused for splice(); see vmsplice(2).
54

RETURN VALUE

56       Upon successful  completion,  splice()  returns  the  number  of  bytes
57       spliced  to or from the pipe.  A return value of 0 means that there was
58       no data to transfer, and it would not  make  sense  to  block,  because
59       there are no writers connected to the write end of the pipe referred to
60       by fd_in.
61
62       On error, splice() returns -1 and errno is set to indicate the error.
63

ERRORS

65       EBADF  One or both file descriptors are  not  valid,  or  do  not  have
66              proper read-write mode.
67
68       EINVAL Target  file  system  doesn't  support  splicing; target file is
69              opened in append mode; neither of the descriptors  refers  to  a
70              pipe; or offset given for nonseekable device.
71
72       ENOMEM Out of memory.
73
74       ESPIPE Either  off_in  or  off_out  was not NULL, but the corresponding
75              file descriptor refers to a pipe.
76

VERSIONS

78       The splice() system call first appeared in Linux 2.6.17;  library  sup‐
79       port was added to glibc in version 2.5.
80

CONFORMING TO

82       This system call is Linux-specific.
83

NOTES

85       The three system calls splice(), vmsplice(2), and tee(2), provide user-
86       space programs with full  control  over  an  arbitrary  kernel  buffer,
87       implemented  within  the  kernel  using the same type of buffer that is
88       used for a pipe.  In overview, these system calls perform the following
89       tasks:
90
91       splice()    moves data from the buffer to an arbitrary file descriptor,
92                   or vice versa, or from one buffer to another.
93
94       tee(2)      "copies" the data from one buffer to another.
95
96       vmsplice(2) "copies" data from user space into the buffer.
97
98       Though we talk of copying, actual copies are  generally  avoided.   The
99       kernel  does  this by implementing a pipe buffer as a set of reference-
100       counted pointers  to  pages  of  kernel  memory.   The  kernel  creates
101       "copies"  of pages in a buffer by creating new pointers (for the output
102       buffer) referring to the pages, and increasing the reference counts for
103       the pages: only pointers are copied, not the pages of the buffer.
104

EXAMPLE

106       See tee(2).
107

SEE ALSO

109       sendfile(2), tee(2), vmsplice(2)
110

COLOPHON

112       This  page  is  part of release 3.53 of the Linux man-pages project.  A
113       description of the project, and information about reporting  bugs,  can
114       be found at http://www.kernel.org/doc/man-pages/.
115
116
117
118Linux                             2012-05-04                         SPLICE(2)
Impressum