diff options
author | Mehrdad Afshari <mehrdada@users.noreply.github.com> | 2018-01-17 09:26:44 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-17 09:26:44 -0800 |
commit | c24630f5a5ba2e15743d2c5d0e59e1c6a014c353 (patch) | |
tree | dc46786f6d8d7a64dd0715760ca0040f4485553a | |
parent | 8afe8d35e13d52fa61c72f9570bc900253ffebb9 (diff) | |
parent | 1957fd0a84c674676e155665d8d26588f8e03309 (diff) |
Merge pull request #14041 from mehrdada/enable-epoll
Enable epoll on Python manylinux1
-rw-r--r-- | src/core/lib/iomgr/ev_epoll1_linux.cc | 26 | ||||
-rw-r--r-- | src/core/lib/iomgr/port.h | 5 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 1ab7e516de..6ec25d761f 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -26,6 +26,7 @@ #include <assert.h> #include <errno.h> +#include <fcntl.h> #include <limits.h> #include <poll.h> #include <pthread.h> @@ -84,11 +85,32 @@ typedef struct epoll_set { /* The global singleton epoll set */ static epoll_set g_epoll_set; +static int epoll_create_and_set_flag() { +#ifdef GRPC_LINUX_EPOLL_CREATE1 + int fd = epoll_create1(EPOLL_CLOEXEC); + if (fd >= 0) { + return fd; + } + gpr_log(GPR_ERROR, "epoll_create1 unavailable"); + return -1; +#else + int fd = epoll_create(MAX_EPOLL_EVENTS); + if (fd < 0) { + gpr_log(GPR_ERROR, "epoll_create unavailable"); + return -1; + } + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == 0) { + return fd; + } + gpr_log(GPR_ERROR, "fcntl following epoll_create failed"); + return -1; +#endif +} + /* Must be called *only* once */ static bool epoll_set_init() { - g_epoll_set.epfd = epoll_create1(EPOLL_CLOEXEC); + g_epoll_set.epfd = epoll_create_and_set_flag(); if (g_epoll_set.epfd < 0) { - gpr_log(GPR_ERROR, "epoll unavailable"); return false; } diff --git a/src/core/lib/iomgr/port.h b/src/core/lib/iomgr/port.h index 9fae8c0052..80867ee09f 100644 --- a/src/core/lib/iomgr/port.h +++ b/src/core/lib/iomgr/port.h @@ -67,8 +67,11 @@ #define GRPC_POSIX_WAKEUP_FD 1 #define GRPC_TIMER_USE_GENERIC 1 #ifdef __GLIBC_PREREQ -#if __GLIBC_PREREQ(2, 9) +#if __GLIBC_PREREQ(2, 4) #define GRPC_LINUX_EPOLL 1 +#endif +#if __GLIBC_PREREQ(2, 9) +#define GRPC_LINUX_EPOLL_CREATE1 1 #define GRPC_LINUX_EVENTFD 1 #endif #if __GLIBC_PREREQ(2, 10) |