diff --git a/CMakeLists.txt b/CMakeLists.txt index 38fb5a09b..ce356c7b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -788,6 +788,7 @@ CHECK_FUNCTION_EXISTS(atoll LWS_HAVE_ATOLL) CHECK_FUNCTION_EXISTS(_atoi64 LWS_HAVE__ATOI64) CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64) CHECK_FUNCTION_EXISTS(clock_gettime LWS_HAVE_CLOCK_GETTIME) +CHECK_FUNCTION_EXISTS(eventfd LWS_HAVE_EVENTFD) if (NOT LWS_HAVE_GETIFADDRS) if (LWS_WITHOUT_BUILTIN_GETIFADDRS) diff --git a/cmake/lws_config.h.in b/cmake/lws_config.h.in index 16c68dcf5..dbb5701a7 100644 --- a/cmake/lws_config.h.in +++ b/cmake/lws_config.h.in @@ -52,6 +52,7 @@ #cmakedefine LWS_HAVE_NEW_UV_VERSION_H #cmakedefine LWS_HAVE_OPENSSL_ECDH_H #cmakedefine LWS_HAVE_PIPE2 +#cmakedefine LWS_HAVE_EVENTFD #cmakedefine LWS_HAVE_PTHREAD_H #cmakedefine LWS_HAVE_RSA_SET0_KEY #cmakedefine LWS_HAVE_RSA_verify_pss_mgf1 diff --git a/lib/plat/unix/private.h b/lib/plat/unix/private.h index 73fdfbb60..5b3281d64 100644 --- a/lib/plat/unix/private.h +++ b/lib/plat/unix/private.h @@ -43,6 +43,9 @@ #include #include #include +#if defined(LWS_HAVE_EVENTFD) +#include +#endif #if defined(__APPLE__) #include diff --git a/lib/plat/unix/unix-pipe.c b/lib/plat/unix/unix-pipe.c index 64ce253be..f6d3d40c8 100644 --- a/lib/plat/unix/unix-pipe.c +++ b/lib/plat/unix/unix-pipe.c @@ -27,8 +27,11 @@ int lws_plat_pipe_create(struct lws *wsi) { struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - -#if defined(LWS_HAVE_PIPE2) +#if defined(LWS_HAVE_EVENTFD) + pt->dummy_pipe_fds[0] = eventfd(0, EFD_CLOEXEC|EFD_NONBLOCK); + pt->dummy_pipe_fds[1] = -1; + return pt->dummy_pipe_fds[0]<0?-1:0; +#elif defined(LWS_HAVE_PIPE2) return pipe2(pt->dummy_pipe_fds, O_NONBLOCK); #else return pipe(pt->dummy_pipe_fds); @@ -39,12 +42,17 @@ int lws_plat_pipe_signal(struct lws *wsi) { struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; +#if defined(LWS_HAVE_EVENTFD) + eventfd_t value = 1; + return eventfd_write(pt->dummy_pipe_fds[0], value); +#else char buf = 0; int n; n = write(pt->dummy_pipe_fds[1], &buf, 1); return n != 1; +#endif } void diff --git a/lib/roles/pipe/ops-pipe.c b/lib/roles/pipe/ops-pipe.c index 012050b0a..88aab5f24 100644 --- a/lib/roles/pipe/ops-pipe.c +++ b/lib/roles/pipe/ops-pipe.c @@ -25,7 +25,11 @@ static int rops_handle_POLLIN_pipe(struct lws_context_per_thread *pt, struct lws *wsi, struct lws_pollfd *pollfd) { -#if !defined(WIN32) && !defined(_WIN32) +#if defined(LWS_HAVE_EVENTFD) + eventfd_t value; + if (eventfd_read(wsi->desc.sockfd, &value) < 0) + return LWS_HPI_RET_PLEASE_CLOSE_ME; +#elif !defined(WIN32) && !defined(_WIN32) char s[100]; int n;