diff options
| author | Sterling Hughes <sterling@bumblebury.com> | 2002-01-07 20:52:32 +0000 | 
|---|---|---|
| committer | Sterling Hughes <sterling@bumblebury.com> | 2002-01-07 20:52:32 +0000 | 
| commit | 8d7f402efbcace85851c6bb8f6aa2452c15a9595 (patch) | |
| tree | 4faf3a7b90bca33494801df5e0b58415d3ff39c3 /lib/hostip.c | |
| parent | d3299beec734be02a781c393a994d525e3eaaac1 (diff) | |
Make cach'ing work with threads now, there are now three cases:
    - Use a global dns cache (via setting the tentatively named,
    CURLOPT_DNS_USE_GLOBAL_CACHE option to true)
    - Use a per-handle dns cache, by default
    - Use a pooled dns cache when in the "multi" interface
Diffstat (limited to 'lib/hostip.c')
| -rw-r--r-- | lib/hostip.c | 26 | 
1 files changed, 19 insertions, 7 deletions
| diff --git a/lib/hostip.c b/lib/hostip.c index db02b8681..791ee030c 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -70,17 +70,27 @@  #endif  static curl_hash hostname_cache; +static int host_cache_initialized; -void Curl_host_cache_init(void) +void Curl_global_host_cache_init(void)  { -  curl_hash_init(&hostname_cache, 7, Curl_freeaddrinfo); +  if (!host_cache_initialized) { +    curl_hash_init(&hostname_cache, 7, Curl_freeaddrinfo); +    host_cache_initialized = 1; +  }  } -void Curl_host_cache_dtor(void) +curl_hash *Curl_global_host_cache_get(void)  { -  curl_hash_clean(&hostname_cache); +  return &hostname_cache;  } +void Curl_global_host_cache_dtor(void) +{ +  if (host_cache_initialized) { +    curl_hash_clean(&hostname_cache); +  } +}  Curl_addrinfo *Curl_resolv(struct SessionHandle *data,                             char *hostname, @@ -90,14 +100,15 @@ Curl_addrinfo *Curl_resolv(struct SessionHandle *data,    Curl_addrinfo *addr = NULL;    size_t hostname_len = strlen(hostname)+1; -  if (curl_hash_find(&hostname_cache, hostname, hostname_len, (void **) &addr)) +  if (curl_hash_find(data->hostcache, hostname, hostname_len, (void **) &addr)) {      return addr; - +  } +      addr = Curl_getaddrinfo(data, hostname, port, bufp);    if (!addr)      return NULL; -  curl_hash_add(&hostname_cache, hostname, hostname_len, (const void *) addr); +  curl_hash_add(data->hostcache, hostname, hostname_len, (const void *) addr);    return addr;  } @@ -405,3 +416,4 @@ Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,   * vim600: fdm=marker   * vim: et sw=2 ts=2 sts=2 tw=78   */ +  | 
