aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/easy.c20
-rw-r--r--lib/hostip.c14
-rw-r--r--lib/hostip.h8
-rw-r--r--lib/url.c9
-rw-r--r--lib/urldata.h1
5 files changed, 23 insertions, 29 deletions
diff --git a/lib/easy.c b/lib/easy.c
index 991a25573..b8af38038 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -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) {
diff --git a/lib/hostip.c b/lib/hostip.c
index aa5ec1e00..0778fc222 100644
--- a/lib/hostip.c
+++ b/lib/hostip.c
@@ -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;
}
/*
diff --git a/lib/hostip.h b/lib/hostip.h
index a7e0988a2..66d1771a3 100644
--- a/lib/hostip.h
+++ b/lib/hostip.h
@@ -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;
diff --git a/lib/url.c b/lib/url.c
index 94c363fc2..83ebcfefa 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -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:
diff --git a/lib/urldata.h b/lib/urldata.h
index f3ca2f80d..e9e4fb872 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -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