]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
asyn-ares: with modern c-ares, use its default timeout
authorLin Sun <sunlin7@hotmail.com>
Mon, 15 Jan 2024 06:58:09 +0000 (06:58 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 16 Jan 2024 09:45:58 +0000 (10:45 +0100)
Closes #12703

lib/asyn-ares.c

index f1ff49277c491ee3edc46969e01e5857ff456804..76efba78ad5dc1b630bcb2a17c347a1b5e779e2c 100644 (file)
@@ -173,10 +173,26 @@ CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver)
   int status;
   struct ares_options options;
   int optmask = ARES_OPT_SOCK_STATE_CB;
+  static int ares_ver = 0;
   options.sock_state_cb = sock_state_cb;
   options.sock_state_cb_data = easy;
-  options.timeout = CARES_TIMEOUT_PER_ATTEMPT;
-  optmask |= ARES_OPT_TIMEOUTMS;
+  if(ares_ver == 0)
+    ares_version(&ares_ver);
+
+  if(ares_ver < 0x011400) { /* c-ares included similar change since 1.20.0 */
+    options.timeout = CARES_TIMEOUT_PER_ATTEMPT;
+    optmask |= ARES_OPT_TIMEOUTMS;
+  }
+
+  /*
+     if c ares < 1.20.0: curl set timeout to CARES_TIMEOUT_PER_ATTEMPT (2s)
+
+     if c-ares >= 1.20.0 it already has the timeout to 2s, curl does not need
+     to set the timeout value;
+
+     if c-ares >= 1.24.0, user can set the timeout via /etc/resolv.conf to
+     overwrite c-ares' timeout.
+  */
 
   status = ares_init_options((ares_channel*)resolver, &options, optmask);
   if(status != ARES_SUCCESS) {