From 504e4b326e2c186a1d53e5596abe22f8c2762c95 Mon Sep 17 00:00:00 2001 From: Scott Wichser Date: Tue, 26 Nov 2024 05:40:04 -0600 Subject: [PATCH] Further cleanups on AresHandler Assume that we're not using a 15+ year old c-ares and remove the checks for versions older than 1.7.0. On autotools systems, check for the existance of ares_getaddrinfo. Assume we have it on Windows and macOS. --- MSVC/build/config.h | 2 +- Xcode/config.h | 4 ++-- configure.ac | 2 +- include/AresHandler.h | 15 ++++----------- src/net/AresHandler.cxx | 37 +++++++++++++------------------------ 5 files changed, 21 insertions(+), 39 deletions(-) diff --git a/MSVC/build/config.h b/MSVC/build/config.h index 3c307012db..0d077399d8 100644 --- a/MSVC/build/config.h +++ b/MSVC/build/config.h @@ -108,7 +108,7 @@ #define HAVE_STD__MIN 1 #define HAVE_STD__MAX 1 -#define HAVE_ARES_LIBRARY_INIT 1 +#define HAVE_ARES_GETADDRINFO 1 #ifndef DEBUG_TRACE #define DEBUG_TRACE diff --git a/Xcode/config.h b/Xcode/config.h index 80aa5129f2..70918c5b7e 100644 --- a/Xcode/config.h +++ b/Xcode/config.h @@ -45,8 +45,8 @@ /* libm includes acosf */ #define HAVE_ACOSF 1 -/* Define if libcares includes ares_library_init. */ -#define HAVE_ARES_LIBRARY_INIT 1 +/* Define if libcares includes ares_getaddrinfo */ +#define HAVE_ARES_GETADDRINFO 1 /* libm includes asinf */ #define HAVE_ASINF 1 diff --git a/configure.ac b/configure.ac index 254a250abe..2dd0e6381e 100644 --- a/configure.ac +++ b/configure.ac @@ -290,7 +290,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]])],[AC_MSG_RESULT([yes])],[AC_MSG_FAILURE([working c-ares library was not found])]) LIBS="$PRELIBS" -AC_CHECK_LIB(cares, ares_library_init, AC_DEFINE([HAVE_ARES_LIBRARY_INIT],[1],[Define if libcares includes ares_library_init.])) +AC_CHECK_LIB(cares, ares_getaddrinfo, AC_DEFINE([HAVE_ARES_GETADDRINFO],[1],[Define if libcares includes ares_getaddrinfo.])) diff --git a/include/AresHandler.h b/include/AresHandler.h index 796c3912d1..778198110a 100644 --- a/include/AresHandler.h +++ b/include/AresHandler.h @@ -54,22 +54,15 @@ class AresHandler return status; }; private: -#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 - static void staticCallback1(void *arg, int status, +#if HAVE_ARES_GETADDRINFO + static void staticCallbackAddrInfo(void *arg, int status, int timeout, struct ares_addrinfo *result); + void callbackAddrInfo(int status, struct ares_addrinfo *result); #endif - -#if ARES_VERSION_MAJOR >= 1 && ARES_VERSION_MINOR >= 5 static void staticCallback(void *arg, int statusCallback, int timeouts, struct hostent *hostent); -#else - static void staticCallback(void *arg, int statusCallback, - struct hostent *hostent); -#endif void callback(int status, struct hostent *hostent); -#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 - void callback1(int status, struct ares_addrinfo *result); -#endif + int index; std::string hostName; diff --git a/src/net/AresHandler.cxx b/src/net/AresHandler.cxx index 46fd7fc583..cb81468d92 100644 --- a/src/net/AresHandler.cxx +++ b/src/net/AresHandler.cxx @@ -72,9 +72,7 @@ bool AresHandler::globalInit() { if (!globallyInited) { -#ifdef HAVE_ARES_LIBRARY_INIT if (ares_library_init(ARES_LIB_INIT_ALL) == ARES_SUCCESS) -#endif globallyInited = true; } return globallyInited; @@ -82,10 +80,8 @@ bool AresHandler::globalInit() void AresHandler::globalShutdown() { -#ifdef HAVE_ARES_LIBRARY_INIT if (globallyInited) ares_library_cleanup(); -#endif } void AresHandler::queryHostname(const struct sockaddr *clientAddr) @@ -121,12 +117,12 @@ void AresHandler::queryHost(const char *name) // launch the asynchronous query to look up this hostname status = HbNPending; -#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 +#if HAVE_ARES_GETADDRINFO struct ares_addrinfo_hints hints; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; - ares_getaddrinfo(aresChannel, name, NULL, &hints, staticCallback1, + ares_getaddrinfo(aresChannel, name, NULL, &hints, staticCallbackAddrInfo, (void *)this); #else ares_gethostbyname(aresChannel, name, AF_INET, staticCallback, @@ -134,24 +130,8 @@ void AresHandler::queryHost(const char *name) #endif } -#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 -void AresHandler::staticCallback1(void *arg, int status, - int, struct ares_addrinfo *result) -{ - if (status == ARES_EDESTRUCTION) - return; - - ((AresHandler *)arg)->callback1(status, result); -} -#endif - -#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 5 void AresHandler::staticCallback(void *arg, int callbackStatus, int, struct hostent *hostent) -#else -void AresHandler::staticCallback(void *arg, int callbackStatus, - struct hostent *hostent) -#endif { ((AresHandler *)arg)->callback(callbackStatus, hostent); } @@ -182,8 +162,17 @@ void AresHandler::callback(int callbackStatus, struct hostent *hostent) } } -#if ARES_VERSION_MAJOR > 1 || ARES_VERSION_MINOR >= 16 -void AresHandler::callback1(int callbackStatus, struct ares_addrinfo *result) +#if HAVE_ARES_GETADDRINFO +void AresHandler::staticCallbackAddrInfo(void *arg, int status, + int, struct ares_addrinfo *result) +{ + if (status == ARES_EDESTRUCTION) + return; + + ((AresHandler *)arg)->callbackAddrInfo(status, result); +} + +void AresHandler::callbackAddrInfo(int callbackStatus, struct ares_addrinfo *result) { const std::lock_guard lock(callback_mutex);