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
10       #include <fcntl.h>
11
12       long 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 non-blocking, 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 non-seekable 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.
79

CONFORMING TO

81       This system call is Linux-specific.
82

NOTES

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

EXAMPLE

105       See tee(2).
106

SEE ALSO

108       sendfile(2), tee(2), vmsplice(2), feature_test_macros(7)
109

COLOPHON

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