Skip to content

Instantly share code, notes, and snippets.

@deltheil
Last active March 15, 2019 00:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save deltheil/6183330 to your computer and use it in GitHub Desktop.
Save deltheil/6183330 to your computer and use it in GitHub Desktop.
libcurl options to control DNS lookup (cache, timeout, resolving time, etc). The short URL for this page is: http://git.io/libcurl-dns.

Easy handle interface

Options

Info

Use CURLINFO_NAMELOOKUP_TIME to obtain the name resolving time post-transfer, for a given easy handle.

Multi handle interface

According to the share interface documentation:

When you use the multi interface, all easy handles added to the same multi handle will share DNS cache by default

libcurl internal structs documentation gives some more precisions:

multi->hostcache points to the name cache. It is a hash table for looking up name to IP. The nodes have a limited life time in there and this cache is meant to reduce the time for when the same name is wanted within a short period of time.

From curl/lib/multi.c we can confirm this hostcache does not survive (of course) to the multi handle deletion:

CURLMcode curl_multi_cleanup(CURLM *multi_handle)
{
    ...
    
    Curl_hash_destroy(multi->hostcache);
    multi->hostcache = NULL;
    
    ...
}   

In other words the multi interface DNS cache is NOT global [1].

The source code gives another precision vs. which DNS cache takes precedence:

for multi interface connections, we share DNS cache automatically if the easy handle's one is currently not set.

In other words the multi interface uses its own cache if the caller did not previously set a shared DNS cache on its easy handle via CURLOPT_SHARE.

Share interface

Options

The CURL_LOCK_DATA_DNS share option allows to cache DNS queries between easy handles.

See also this mailing list discussion:

[1]: which is BTW considered as evil by libcurl's TODO: Anything global is silly, and we already offer the share interface for the same functionality but done "right".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment