[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.
This commit is contained in:
Willy Tarreau 2009-01-18 21:59:13 +01:00
parent 259de1b702
commit 6b4aad4c1b

View File

@ -10,6 +10,7 @@
*
*/
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@ -33,6 +34,49 @@
#include <proto/task.h>
/* 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 <unistd.h>
#include <sys/syscall.h>
#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