MEDIUM: listener: add support for linux's accept4() syscall

On Linux, accept4() does the same as accept() except that it allows
the caller to specify some flags to set on the resulting socket. We
use this to set the O_NONBLOCK flag and thus to save one fcntl()
call in each connection. The effect is a small performance gain of
around 1%.

The option is automatically enabled when target linux2628 is set, or
when the USE_ACCEPT4 Makefile variable is set. If the libc is too old
to provide the equivalent function, this is automatically detected and
our own function is used instead. In any case it is possible to force
the use of our implementation with USE_MY_ACCEPT4.
diff --git a/include/common/syscall.h b/include/common/syscall.h
index a3b27eb..3ccbf5a 100644
--- a/include/common/syscall.h
+++ b/include/common/syscall.h
@@ -2,7 +2,7 @@
  * include/common/syscall.h
  * Redefinition of some missing OS-specific system calls.
  *
- * Copyright 2000-2011 Willy Tarreau <w@1wt.eu>
+ * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -124,6 +124,21 @@
 #endif /* $arch */
 #endif /* __NR_splice */
 
+/* accept4() appeared in Linux 2.6.28, but it might not be in all libcs. Some
+ * archs have it as a native syscall, other ones use the socketcall instead.
+ */
+#ifndef __NR_accept4
+#if defined(__x86_64__)
+#define __NR_accept4            288
+#elif defined(__sparc__) || defined(__sparc64__)
+#define __NR_splice             323
+#else
+#define ACCEPT4_USE_SOCKETCALL    1
+#ifndef SYS_ACCEPT4
+#define SYS_ACCEPT4              18
+#endif /* SYS_ACCEPT4 */
+#endif /* $arch */
+#endif /* __NR_accept4 */
 
 #endif /* __linux__ */
 #endif /* _COMMON_SYSCALL_H */