@@ -278,13 +278,15 @@ using socket_t = int;
278278#include < unordered_set>
279279#include < utility>
280280
281+ #if defined(CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO)
281282#if defined(__APPLE__)
282283#include < TargetConditionals.h>
283- #if TARGET_OS_OSX || TARGET_OS_IPHONE
284+ #if TARGET_OS_OSX
284285#include < CFNetwork/CFHost.h>
285286#include < CoreFoundation/CoreFoundation.h>
286287#endif
287288#endif
289+ #endif // CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO
288290
289291#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290292#ifdef _WIN32
@@ -302,14 +304,16 @@ using socket_t = int;
302304#endif
303305#endif // _WIN32
304306
307+ #if defined(CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO)
305308#if defined(__APPLE__)
306- #if defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN)
307309#include < TargetConditionals.h>
308310#if TARGET_OS_OSX
311+ #include < CFNetwork/CFHost.h>
312+ #include < CoreFoundation/CoreFoundation.h>
309313#include < Security/Security.h>
310- #endif // TARGET_OS_OSX
311- #endif // CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN
312- #endif // ___APPLE__
314+ #endif
315+ #endif
316+ #endif // CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO
313317
314318#include < openssl/err.h>
315319#include < openssl/evp.h>
@@ -3383,6 +3387,7 @@ unescape_abstract_namespace_unix_domain(const std::string &s) {
33833387inline int getaddrinfo_with_timeout (const char *node, const char *service,
33843388 const struct addrinfo *hints,
33853389 struct addrinfo **res, time_t timeout_sec) {
3390+ #ifdef CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO
33863391 if (timeout_sec <= 0 ) {
33873392 // No timeout specified, use standard getaddrinfo
33883393 return getaddrinfo (node, service, hints, res);
@@ -3690,6 +3695,10 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service,
36903695 return EAI_AGAIN; // Return timeout error
36913696 }
36923697#endif
3698+ #else
3699+ (void )(timeout_sec); // Unused parameter for non-blocking getaddrinfo
3700+ return getaddrinfo (node, service, hints, res);
3701+ #endif
36933702}
36943703
36953704template <typename BindOrConnect>
@@ -3868,6 +3877,7 @@ inline bool bind_ip_address(socket_t sock, const std::string &host) {
38683877 if (getaddrinfo_with_timeout (host.c_str (), " 0" , &hints, &result, 0 )) {
38693878 return false ;
38703879 }
3880+
38713881 auto se = detail::scope_exit ([&] { freeaddrinfo (result); });
38723882
38733883 auto ret = false ;
0 commit comments