From b360ed2a7bdf03d20b7ba59e656ff7e4ffa63b9b Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Fri, 12 May 2023 15:00:48 -0400 Subject: [PATCH] update detection for sendmsg and sendmmsg (handles some platforms that don't define sendmmsg); --- CMakeLists.txt | 22 ++++++++++++++++++++++ src/network/UDPSocket.h | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6a8a503..ec94671d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,8 @@ file(GLOB dvmhost_SRC "src/host/calibrate/*.cpp" "src/host/setup/*.h" "src/host/setup/*.cpp" + "src/host/fne/*.h" + "src/host/fne/*.cpp" "src/lookups/*.h" "src/lookups/*.cpp" "src/modem/*.h" @@ -106,6 +108,8 @@ file(GLOB dvmhost_SRC "src/modem/port/*.cpp" "src/network/*.h" "src/network/*.cpp" + "src/network/fne/*.h" + "src/network/fne/*.cpp" "src/network/json/*.h" "src/network/rest/*.h" "src/network/rest/*.cpp" @@ -401,6 +405,24 @@ target_include_directories(asio::asio INTERFACE ${ASIO_INCLUDE_DIR}) target_compile_definitions(asio::asio INTERFACE "ASIO_STANDALONE") target_link_libraries(asio::asio INTERFACE Threads::Threads) +# Check if platform-specific functions exist +include(CheckCXXSymbolExists) +check_cxx_symbol_exists(sendmsg sys/socket.h HAVE_SENDMSG) +check_cxx_symbol_exists(sendmmsg sys/socket.h HAVE_SENDMMSG) + +if(HAVE_SENDMSG) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_SENDMSG=1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_SENDMSG=1") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DHAVE_SENDMSG=1") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DHAVE_SENDMSG=1") +endif() +if(HAVE_SENDMMSG) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_SENDMMSG=1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_SENDMMSG=1") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DHAVE_SENDMMSG=1") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DHAVE_SENDMMSG=1") +endif() + add_executable(dvmhost ${dvmhost_SRC}) target_include_directories(dvmhost PRIVATE src) target_link_libraries(dvmhost PRIVATE asio::asio Threads::Threads util) diff --git a/src/network/UDPSocket.h b/src/network/UDPSocket.h index f1e79a59..df57a012 100644 --- a/src/network/UDPSocket.h +++ b/src/network/UDPSocket.h @@ -62,6 +62,29 @@ enum IPMATCHTYPE { namespace network { +#if defined(HAVE_SENDMSG) && !defined(HAVE_SENDMMSG) + struct mmsghdr { + struct msghdr msg_hdr; + unsigned int msg_len; + }; + + static inline int sendmmsg(int sockfd, struct mmsghdr* msgvec, unsigned int vlen, int flags) + { + ssize_t n = 0; + for (unsigned int i = 0; i < vlen; i++) { + ssize_t ret = sendmsg(sockfd, &msgvec[i].msg_hdr, flags); + if (ret < 0) + break; + n += ret; + } + + if (n == 0) + return -1; + + return int(n); + } +#endif + /* Vector of buffers that contain a full frames */ typedef std::vector> BufferVector;