Woops, partly revert my previous commit and do it slightly differently instead.

The signalling of that a global DNS cache is wanted is done by setting the
option but the setting of the internal variable that it is in use must not be
done until it finally actually gets used!

NOTE and WARNING: I noticed that you can't actually switch off the global dns
cache with CURLOPT_DNS_USE_GLOBAL_CACHE but you couldn't do that previously
either and the option is very clearly and loudly documented as DO NOTE USE so
I won't bother to fix this bug now.
This commit is contained in:
Daniel Stenberg 2008-01-15 22:44:12 +00:00
parent 56f17d2c9f
commit 991505e077
5 changed files with 23 additions and 29 deletions

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -466,13 +466,23 @@ CURLcode curl_easy_perform(CURL *curl)
return CURLE_BAD_FUNCTION_ARGUMENT;
if( ! (data->share && data->share->hostcache) ) {
/* this handle is not using a shared dns cache */
if(data->set.global_dns_cache &&
(data->dns.hostcachetype != HCACHE_GLOBAL)) {
/* global dns cache was requested but still isn't */
struct curl_hash *ptr;
if(Curl_global_host_cache_use(data) &&
(data->dns.hostcachetype != HCACHE_GLOBAL)) {
if(data->dns.hostcachetype == HCACHE_PRIVATE)
/* if the current cache is private, kill it first */
Curl_hash_destroy(data->dns.hostcache);
data->dns.hostcache = Curl_global_host_cache_get();
data->dns.hostcachetype = HCACHE_GLOBAL;
ptr = Curl_global_host_cache_init();
if(ptr) {
/* only do this if the global cache init works */
data->dns.hostcache = ptr;
data->dns.hostcachetype = HCACHE_GLOBAL;
}
}
if(!data->dns.hostcache) {

View File

@ -128,9 +128,9 @@ static void freednsentry(void *freethis);
* Global DNS cache is general badness. Do not use. This will be removed in
* a future version. Use the share interface instead!
*
* Returns 0 on success, 1 on failure.
* Returns a struct curl_hash pointer on success, NULL on failure.
*/
int Curl_global_host_cache_init(void)
struct curl_hash *Curl_global_host_cache_init(void)
{
int rc = 0;
if(!host_cache_initialized) {
@ -139,15 +139,7 @@ int Curl_global_host_cache_init(void)
if(!rc)
host_cache_initialized = 1;
}
return rc;
}
/*
* Return a pointer to the global cache
*/
struct curl_hash *Curl_global_host_cache_get(void)
{
return &hostname_cache;
return rc?NULL:&hostname_cache;
}
/*

View File

@ -130,14 +130,10 @@ struct connectdata;
* Global DNS cache is general badness. Do not use. This will be removed in
* a future version. Use the share interface instead!
*
* Returns 0 on success, 1 on failure.
* Returns a struct curl_hash pointer on success, NULL on failure.
*/
int Curl_global_host_cache_init(void);
struct curl_hash *Curl_global_host_cache_init(void);
void Curl_global_host_cache_dtor(void);
struct curl_hash *Curl_global_host_cache_get(void);
#define Curl_global_host_cache_use(__p) \
((__p)->dns.hostcachetype == HCACHE_GLOBAL)
struct Curl_dns_entry {
Curl_addrinfo *addr;

View File

@ -778,14 +778,9 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
break;
case CURLOPT_DNS_USE_GLOBAL_CACHE:
{
/* remember we want this enabled */
long use_cache = va_arg(param, long);
if(use_cache) {
Curl_global_host_cache_init();
data->dns.hostcachetype = HCACHE_GLOBAL;
}
else
/* not global makes it private by default then */
data->dns.hostcachetype = HCACHE_PRIVATE;
data->set.global_dns_cache = (bool)(0 != use_cache);
}
break;
case CURLOPT_SSL_CIPHER_LIST:

View File

@ -1443,6 +1443,7 @@ struct UserDefined {
curl_ftpauth ftpsslauth; /* what AUTH XXX to be attempted */
curl_ftpccc ftp_ccc; /* FTP CCC options */
bool no_signal; /* do not use any signal/alarm handler */
bool global_dns_cache; /* subject for future removal */
bool tcp_nodelay; /* whether to enable TCP_NODELAY or not */
bool ignorecl; /* ignore content length */
bool ftp_skip_ip; /* skip the IP address the FTP server passes on to