From 97c0f89bd05c0710386c258a7d1b36e24c97e730 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 12 Sep 2024 12:24:42 +0200 Subject: [PATCH] quic: use send/recvmmsg when available add checks for sendmmsg in configure and CmakeLists.txt for enabling use of these functions in ngtcp2/quiche quic. Closes #14880 --- CMake/Platforms/WindowsCache.cmake | 1 + CMakeLists.txt | 5 +++++ configure.ac | 9 +++++++++ lib/curl_config.h.cmake | 3 +++ lib/curl_setup.h | 5 +++++ lib/vquic/vquic.c | 12 ------------ src/tool_operate.c | 1 + 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CMake/Platforms/WindowsCache.cmake b/CMake/Platforms/WindowsCache.cmake index 317f21c875..57b2b40bd4 100644 --- a/CMake/Platforms/WindowsCache.cmake +++ b/CMake/Platforms/WindowsCache.cmake @@ -88,6 +88,7 @@ set(HAVE_FREEADDRINFO 1) set(HAVE_FCHMOD 0) set(HAVE_SOCKETPAIR 0) set(HAVE_SENDMSG 0) +set(HAVE_SENDMMSG 0) set(HAVE_ALARM 0) set(HAVE_FCNTL 0) set(HAVE_GETPPID 0) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c291e27b4..15964dd860 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,10 @@ cmake_dependent_option(ENABLE_THREADED_RESOLVER "Enable threaded DNS lookup" include(PickyWarnings) +if(CMAKE_SYSTEM_NAME MATCHES "Linux") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE") # Required for sendmmsg() +endif() + option(ENABLE_DEBUG "Enable curl debug features" OFF) option(ENABLE_CURLDEBUG "Enable TrackMemory feature" ${ENABLE_DEBUG}) @@ -1468,6 +1472,7 @@ check_symbol_exists("socketpair" "${CURL_INCLUDES}" HAVE_SOCKETPAIR) check_symbol_exists("recv" "${CURL_INCLUDES}" HAVE_RECV) check_symbol_exists("send" "${CURL_INCLUDES}" HAVE_SEND) check_symbol_exists("sendmsg" "${CURL_INCLUDES}" HAVE_SENDMSG) +check_symbol_exists("sendmmsg" "sys/socket.h" HAVE_SENDMMSG) check_symbol_exists("select" "${CURL_INCLUDES}" HAVE_SELECT) check_symbol_exists("strdup" "${CURL_INCLUDES};string.h" HAVE_STRDUP) check_symbol_exists("strtok_r" "${CURL_INCLUDES};string.h" HAVE_STRTOK_R) diff --git a/configure.ac b/configure.ac index e558032e51..09db30cc40 100644 --- a/configure.ac +++ b/configure.ac @@ -573,6 +573,14 @@ case $host_os in ;; esac +# In order to detect support of sendmmsg(), we need to escape the POSIX +# jail by defining _GNU_SOURCE or will not expose it. +case $host_os in + linux*) + CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" + ;; +esac + dnl Build unit tests when option --enable-debug is given. if test "x$want_debug" = "xyes" && test "x$supports_unittests" = "xyes"; then @@ -4102,6 +4110,7 @@ AC_CHECK_FUNCS([\ pipe \ sched_yield \ sendmsg \ + sendmmsg \ setlocale \ setmode \ setrlimit \ diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index 9c785f334e..ef7a7a6933 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -463,6 +463,9 @@ /* Define to 1 if you have the sendmsg function. */ #cmakedefine HAVE_SENDMSG 1 +/* Define to 1 if you have the sendmmsg function. */ +#cmakedefine HAVE_SENDMMSG 1 + /* Define to 1 if you have the 'fsetxattr' function. */ #cmakedefine HAVE_FSETXATTR 1 diff --git a/lib/curl_setup.h b/lib/curl_setup.h index c9771d7544..1c715fd4fe 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -208,6 +208,11 @@ /* please, do it beyond the point further indicated in this file. */ /* ================================================================ */ +/* Give calloc a chance to be dragging in early, so we do not redefine */ +#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) +# include +#endif + /* * Disable other protocols when http is the only one desired. */ diff --git a/lib/vquic/vquic.c b/lib/vquic/vquic.c index 4648b5a072..715328bc9e 100644 --- a/lib/vquic/vquic.c +++ b/lib/vquic/vquic.c @@ -22,18 +22,6 @@ * ***************************************************************************/ -/* WIP, experimental: use recvmmsg() on Linux - * we have no configure check, yet - * and also it is only available for _GNU_SOURCE, which - * we do not use otherwise. -#define HAVE_SENDMMSG - */ -#if defined(HAVE_SENDMMSG) -#define _GNU_SOURCE -#include -#undef _GNU_SOURCE -#endif - #include "curl_setup.h" #ifdef HAVE_NETINET_UDP_H diff --git a/src/tool_operate.c b/src/tool_operate.c index 90b6efdade..5b51243374 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -169,6 +169,7 @@ static int get_address_family(curl_socket_t sockfd) { struct sockaddr addr; curl_socklen_t addrlen = sizeof(addr); + memset(&addr, 0, sizeof(addr)); if(getsockname(sockfd, (struct sockaddr *)&addr, &addrlen) == 0) return addr.sa_family; return AF_UNSPEC; -- 2.47.3