]> granicus.if.org Git - curl/commitdiff
added a library-wide interface for doing dns cache pruning, and no longer
authorDaniel Stenberg <daniel@haxx.se>
Mon, 15 Dec 2003 17:33:49 +0000 (17:33 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 15 Dec 2003 17:33:49 +0000 (17:33 +0000)
make the pruning at each name lookup, only in Curl_done().

lib/hostip.c
lib/hostip.h
lib/url.c

index f2fa350d0752e9b477ae59ccd1a649a9542d1953..bc0db192516a445a254899a5ce0c23ecf5635e84 100644 (file)
@@ -195,6 +195,23 @@ hostcache_prune(curl_hash *hostcache, int cache_timeout, int now)
                                  hostcache_timestamp_remove);
 }
 
+void Curl_hostcache_prune(struct SessionHandle *data)
+{
+  time_t now;
+  if(data->share)
+    Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
+
+  time(&now);
+
+  /* Remove outdated and unused entries from the hostcache */
+  hostcache_prune(data->hostcache,
+                  data->set.dns_cache_timeout,
+                  now);
+
+  if(data->share)
+    Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+}
+
 #ifdef HAVE_SIGSETJMP
 /* Beware this is a global and unique instance */
 sigjmp_buf curl_jmpenv;
@@ -249,12 +266,6 @@ cache_resolv_response(struct SessionHandle *data,
   dns->timestamp = now; /* used now */
   dns->inuse++;         /* mark entry as in-use */
 
-    
-  /* Remove outdated and unused entries from the hostcache */
-  hostcache_prune(data->hostcache, 
-                  data->set.dns_cache_timeout, 
-                  now);
-
   /* free the allocated entry_id again */
   free(entry_id);
 
index f902b5c6443eaf50da68cf7845fcf1c33ecb403b..c033bc25a75298eae57e44c89011f4ef3537e632 100644 (file)
@@ -77,6 +77,9 @@ void Curl_freeaddrinfo(Curl_addrinfo *freeaddr);
 /* free cached name info */
 void Curl_freednsinfo(void *freethis);
 
+/* prune old entries from the DNS cache */
+void Curl_hostcache_prune(struct SessionHandle *data);
+
 #ifdef CURLDEBUG
 void curl_freeaddrinfo(struct addrinfo *freethis,
                        int line, const char *source);
index d21cab247fef1c57f2fd55fd543a5a3f55a43183..417121cb341b4933b46d0384d208066e590ef702 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3227,6 +3227,8 @@ CURLcode Curl_done(struct connectdata *conn)
                   NULL, Curl_scan_cache_used);
 #endif
 
+  Curl_hostcache_prune(data); /* kill old DNS cache entries */
+
   /* this calls the protocol-specific function pointer previously set */
   if(conn->curl_done)
     result = conn->curl_done(conn);