diff --git a/CMakeLists.txt b/CMakeLists.txt index 3424c225f..7e865d615 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -567,6 +567,7 @@ include(CheckIncludeFile) include(CheckIncludeFiles) include(CheckLibraryExists) include(CheckTypeSize) +include(CheckCSourceCompiles) if (LWS_WITHOUT_BUILTIN_SHA1) set(LWS_SHA1_USE_OPENSSL_NAME 1) @@ -1359,6 +1360,11 @@ else() CHECK_FUNCTION_EXISTS(TLS_client_method LWS_HAVE_TLS_CLIENT_METHOD) CHECK_FUNCTION_EXISTS(TLSv1_2_client_method LWS_HAVE_TLSV1_2_CLIENT_METHOD) endif() + +# ideally we want to use pipe2() + +CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE\n#include \nint main(void) {int fd[2];\n return pipe2(fd, 0);\n}\n" LWS_HAVE_PIPE2) + set(CMAKE_REQUIRED_LIBRARIES ${temp}) # Generate the lws_config.h that includes all the public compilation settings. configure_file( diff --git a/cmake/lws_config.h.in b/cmake/lws_config.h.in index ed99139d8..fb16dde3e 100644 --- a/cmake/lws_config.h.in +++ b/cmake/lws_config.h.in @@ -164,6 +164,8 @@ #cmakedefine LWS_HAVE_MALLOC_H +#cmakedefine LWS_HAVE_PIPE2 + /* OpenSSL various APIs */ #cmakedefine LWS_HAVE_TLS_CLIENT_METHOD diff --git a/lib/plat/lws-plat-unix.c b/lib/plat/lws-plat-unix.c index 6b8eff88d..a252e672e 100644 --- a/lib/plat/lws-plat-unix.c +++ b/lib/plat/lws-plat-unix.c @@ -19,6 +19,7 @@ * MA 02110-1301 USA */ +#define _GNU_SOURCE #include "private-libwebsockets.h" #include @@ -40,7 +41,11 @@ lws_plat_pipe_create(struct lws *wsi) { struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; +#if defined(LWS_HAVE_PIPE2) + return pipe2(pt->dummy_pipe_fds, O_NONBLOCK); +#else return pipe(pt->dummy_pipe_fds); +#endif } int diff --git a/lib/roles/pipe/ops-pipe.c b/lib/roles/pipe/ops-pipe.c index aaccb5b5a..273d0d637 100644 --- a/lib/roles/pipe/ops-pipe.c +++ b/lib/roles/pipe/ops-pipe.c @@ -26,7 +26,7 @@ rops_handle_POLLIN_pipe(struct lws_context_per_thread *pt, struct lws *wsi, struct lws_pollfd *pollfd) { #if !defined(WIN32) && !defined(_WIN32) - char s[10]; + char s[100]; int n; /*