From 6b4aad4c1bd39c84e2d0eb8b5df0fce2a397fdfd Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 18 Jan 2009 21:59:13 +0100 Subject: [PATCH] [MEDIUM] add definitions for Linux kernel splicing Some older libc don't define the splice() syscall, and some even define a wrong one. For this reason, we try our best to declare it correctly. These definitions still work with recent glibc. --- src/stream_sock.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/stream_sock.c b/src/stream_sock.c index a02b56a79..550436928 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -10,6 +10,7 @@ * */ +#define _GNU_SOURCE #include #include #include @@ -33,6 +34,49 @@ #include +/* On recent Linux kernels, the splice() syscall may be used for faster data copy. + * But it's not always defined on some OS versions, and it even happens that some + * definitions are wrong with some glibc due to an offset bug in syscall(). + */ + +#if defined(CONFIG_HAP_LINUX_SPLICE) +#include +#include + +#ifndef SPLICE_F_MOVE +#define SPLICE_F_MOVE 0x1 +#endif + +#ifndef SPLICE_F_NONBLOCK +#define SPLICE_F_NONBLOCK 0x2 +#endif + +#ifndef SPLICE_F_MORE +#define SPLICE_F_MORE 0x4 +#endif + +#ifndef __NR_splice +#if defined(__powerpc__) || defined(__powerpc64__) +#define __NR_splice 283 +#elif defined(__sparc__) || defined(__sparc64__) +#define __NR_splice 232 +#elif defined(__x86_64__) +#define __NR_splice 275 +#elif defined(__alpha__) +#define __NR_splice 468 +#elif defined (__i386__) +#define __NR_splice 313 +#else +#warning unsupported architecture, guessing __NR_splice=313 like x86... +#define __NR_splice 313 +#endif /* $arch */ + +_syscall6(int, splice, int, fdin, loff_t *, off_in, int, fdout, loff_t *, off_out, size_t, len, unsigned long, flags) + +#endif /* __NR_splice */ +#endif /* CONFIG_HAP_LINUX_SPLICE */ + + /* * this function is called on a read event from a stream socket. * It returns 0 if we have a high confidence that we will not be