From 6490c6a38e8b936ef1ad6000530a6dc50b3460d2 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 26 Aug 2011 00:16:07 +0200 Subject: [PATCH] unix: improve accept4 syscall feature check --- src/uv-unix.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/uv-unix.c b/src/uv-unix.c index 3044363b..f45aa227 100644 --- a/src/uv-unix.c +++ b/src/uv-unix.c @@ -44,14 +44,26 @@ #include /* writev */ #include -#ifdef __linux__ +#if defined(__linux__) + #include +#include + +#undef HAVE_PIPE2 +#undef HAVE_ACCEPT4 + /* pipe2() requires linux >= 2.6.27 and glibc >= 2.9 */ -#if defined(LINUX_VERSION_CODE) && defined(__GLIBC_PREREQ) && LINUX_VERSION_CODE >= 0x2061B && __GLIBC_PREREQ(2, 9) +#if LINUX_VERSION_CODE >= 0x2061B && __GLIBC_PREREQ(2, 9) #define HAVE_PIPE2 #endif + +/* accept4() requires linux >= 2.6.28 and glib >= 2.10 */ +#if LINUX_VERSION_CODE >= 0x2061C && __GLIBC_PREREQ(2, 10) +#define HAVE_ACCEPT4 #endif +#endif /* __linux__ */ + #ifdef __sun # include # include @@ -2601,7 +2613,7 @@ static int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) { assert(sockfd >= 0); do { -#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) +#if defined(HAVE_ACCEPT4) peerfd = accept4(sockfd, saddr, &slen, SOCK_NONBLOCK | SOCK_CLOEXEC); #else if ((peerfd = accept(sockfd, saddr, &slen)) != -1) {