Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/common/splice.h |
| 3 | * Splice definition for older Linux libc. |
| 4 | * |
| 5 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifndef _COMMON_SPLICE_H |
| 24 | #define _COMMON_SPLICE_H |
| 25 | |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 26 | #if defined (__linux__) && defined(USE_LINUX_SPLICE) |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 27 | |
| 28 | #include <errno.h> |
| 29 | #include <unistd.h> |
| 30 | #include <sys/syscall.h> |
| 31 | #include <common/syscall.h> |
| 32 | |
| 33 | /* On recent Linux kernels, the splice() syscall may be used for faster data copy. |
| 34 | * But it's not always defined on some OS versions, and it even happens that some |
| 35 | * definitions are wrong with some glibc due to an offset bug in syscall(). |
| 36 | */ |
| 37 | |
| 38 | #ifndef SPLICE_F_MOVE |
| 39 | #define SPLICE_F_MOVE 0x1 |
| 40 | #endif |
| 41 | |
| 42 | #ifndef SPLICE_F_NONBLOCK |
| 43 | #define SPLICE_F_NONBLOCK 0x2 |
| 44 | #endif |
| 45 | |
| 46 | #ifndef SPLICE_F_MORE |
| 47 | #define SPLICE_F_MORE 0x4 |
| 48 | #endif |
| 49 | |
| 50 | #if defined(USE_MY_SPLICE) |
| 51 | |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 52 | #if defined(USE_LINUX_VSYSCALL) && defined(__linux__) && defined(__i386__) |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 53 | /* The syscall is redefined somewhere else */ |
| 54 | extern int splice(int fdin, loff_t *off_in, int fdout, loff_t *off_out, size_t len, unsigned long flags); |
| 55 | #else |
| 56 | |
| 57 | /* We'll define a syscall, so for this we need __NR_splice. It should have |
| 58 | * been provided by syscall.h. |
| 59 | */ |
| 60 | #ifndef __NR_splice |
| 61 | #warning unsupported architecture, guessing __NR_splice=313 like x86... |
| 62 | #define __NR_splice 313 |
| 63 | #endif /* __NR_splice */ |
| 64 | |
Willy Tarreau | cefad67 | 2014-05-08 22:36:29 +0200 | [diff] [blame] | 65 | static inline _syscall6(int, splice, int, fdin, loff_t *, off_in, int, fdout, loff_t *, off_out, size_t, len, unsigned long, flags); |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 66 | #endif /* VSYSCALL */ |
| 67 | |
| 68 | #else |
| 69 | /* use the system's definition */ |
| 70 | #include <fcntl.h> |
| 71 | |
| 72 | #endif /* USE_MY_SPLICE */ |
| 73 | |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 74 | #endif /* __linux__ && USE_LINUX_SPLICE */ |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 75 | |
| 76 | #endif /* _COMMON_SPLICE_H */ |
| 77 | |
| 78 | /* |
| 79 | * Local variables: |
| 80 | * c-indent-level: 8 |
| 81 | * c-basic-offset: 8 |
| 82 | * End: |
| 83 | */ |