From 1cb29b6f5cd672faa007d7e0f8fd43e271e5c593 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sun, 14 May 2023 15:13:50 +0000 Subject: [PATCH] net.c: Fix building without TCP enabled for EPOLL configured code Report when using autotools or cmake that disabling TCP also disables Websockets support. Also, report for cmake when EPOLL support is not available. --- CMakeLists.txt | 10 +++++++++- configure.ac | 11 +++++++++-- src/net.c | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 093408e8..f3d99809 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -283,10 +283,14 @@ else() message(STATUS "compiling without OSCORE support") endif() -if(${ENABLE_WS}) +if(${ENABLE_WS} AND $(ENABLE_TCP)) set(COAP_WS_SUPPORT "1") message(STATUS "compiling with WebSockets support") else() + if(${ENABLE_WS}) + set(ENABLE_WS OFF) + message(STATUS "WebSockets disabled as TCP not enabled") + endif() message(STATUS "compiling without WebSockets support") endif() @@ -303,6 +307,10 @@ if(${WITH_EPOLL} set(COAP_EPOLL_SUPPORT "1") message(STATUS "compiling with epoll support") else() + if(${WITH_EPOLL}) + set(WITH_EPOLL OFF) + message(STATUS "epoll disabled as kernel support not available") + endif() message(STATUS "compiling without epoll support") endif() diff --git a/configure.ac b/configure.ac index 2bdbdb42..41ab240c 100644 --- a/configure.ac +++ b/configure.ac @@ -772,8 +772,15 @@ AC_ARG_ENABLE([websockets], [build_ws="$enableval"], [build_ws="yes"]) -AC_DEFINE(COAP_WS_SUPPORT, [1], [Define to 1 to build with WebSockets support.]) -AS_IF([test "x$build_ws" = "xyes"], [AC_DEFINE(COAP_WS_SUPPORT, [1])]) +if test "x$build_ws" = "xyes"; then + if test "x$build_tcp" != "xyes"; then + build_ws=no + AC_MSG_WARN([--enable-websockets requires --enable-tcp, so --enable-websockets ignored.]) + fi +fi + +AS_IF([test "x$build_ws" = "xyes"], + [AC_DEFINE(COAP_WS_SUPPORT, [1], [Define to 1 to build with WebSockets support.])]) AC_SUBST(COAP_WS_SUPPORT) # configure options diff --git a/src/net.c b/src/net.c index 0918adaa..f0c93d94 100644 --- a/src/net.c +++ b/src/net.c @@ -1987,11 +1987,13 @@ coap_io_do_epoll(coap_context_t *ctx, struct epoll_event *events, size_t nevents coap_write_endpoint(endpoint->context, endpoint, now); } +#if !COAP_DISABLE_TCP if ((sock->flags & COAP_SOCKET_WANT_ACCEPT) && (events[j].events & EPOLLIN)) { sock->flags |= COAP_SOCKET_CAN_ACCEPT; coap_accept_endpoint(endpoint->context, endpoint, now); } +#endif /* !COAP_DISABLE_TCP */ } else