cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH]Async-DNS-resolve-thread gets started even when a dotted IP is provided

From: Christian Hägele <haegele_at_teamviewer.com>
Date: Tue, 2 Aug 2011 12:51:37 +0000 (UTC)

Hello,

I am using the curl-multi-API on windows to do a lot of http-requests to
a lot of different hosts. All hosts are identified directly via IPv4-addresses
instead of DNS-entries. Unfortunately curl fires up a new thread to simulate
async-DNS-resolve. In my case that should not be necessary, because I already
provide the dotted IPv4-address. (I 'm not using c-ares).
That thread-start costs a lot of CPU-time for me and can be patched easily.

As I looked at the source this happens in asyn-thread.c in function
Curl_resolver_getaddrinfo.
I don't see any reason against calling Curl_inet_pton before starting a new
thread to check if we already have a dotted IP. Thats the same what already
happens in the asyn-ares.c solution. I have a patch against the nightly build
of august 2nd attached. I am not used to IPv6 and hope the patch didn't break
anything with IPv6.

Regards,

Christian Hägele

--- curl-7.21.8-20110802\lib\asyn-thread.c Wed Jul 27 04:00:16 2011
+++ curl-7.21.8-20110802_patched\lib\asyn-thread.c Tue Aug 02 14:44:45 2011
@@ -626,14 +626,28 @@
                                          int *waitp)
 {
   struct addrinfo hints;
+ struct in_addr in;
   Curl_addrinfo *res;
   int error;
   char sbuf[NI_MAXSERV];
   int pf = PF_INET;
+#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
+ struct in6_addr in6;
+#endif /* CURLRES_IPV6 */
 
   *waitp = 0; /* default to synchronous response */
 
+ /* First check if this is an IPv4 address string */
+ if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
+ /* This is a dotted IP address 123.123.123.123-style */
+ return Curl_ip2addr(AF_INET, &in, hostname, port);
+
 #ifndef CURLRES_IPV4
+ /* Otherwise, check if this is an IPv6 address string */
+ if(Curl_inet_pton (AF_INET6, hostname, &in6) > 0)
+ /* This must be an IPv6 address literal. */
+ return Curl_ip2addr(AF_INET6, &in6, hostname, port);
+
   /*
    * Check if a limited name resolve has been requested.
    */

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-08-02