summaryrefslogtreecommitdiff
path: root/src/htslib.c
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2013-09-06 18:51:07 +0000
committerXavier Roche <xroche@users.noreply.github.com>2013-09-06 18:51:07 +0000
commitc0154f5e778624c6e1c7e69468b99b011452f03f (patch)
tree2b2832efde9de6db6b53039aa95ba2cf73ff34a8 /src/htslib.c
parentbd28ac98ded17e44c66d4b8b7e6a739b45dc8ae0 (diff)
Finished to cleanup the DNS cache.
Diffstat (limited to 'src/htslib.c')
-rw-r--r--src/htslib.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/htslib.c b/src/htslib.c
index 2c61ec2..c1ce400 100644
--- a/src/htslib.c
+++ b/src/htslib.c
@@ -4641,12 +4641,12 @@ static t_hostent *hts_ghbn(t_dnscache * cache, const char *iadr, t_hostent * ret
}
// tester si iadr a déja été testé (ou en cours de test)
-// 0 non encore
+// 0 non encore (en cours)
// 1 ok
// 2 non présent
-int hts_dnstest(httrackp * opt, const char *_iadr) {
+int hts_dnstest(httrackp * opt, const char *_iadr, int add) {
int ret = 2;
- t_dnscache *cache;
+ t_dnscache *cache, *tail;
char iadr[HTS_URLMAXSIZE * 2];
// sauter user:pass@ éventuel
@@ -4667,12 +4667,30 @@ int hts_dnstest(httrackp * opt, const char *_iadr) {
return 1;
hts_mutexlock(&opt->state.lock);
- for(cache = _hts_cache(opt); cache != NULL; cache = cache->n) {
+ for(cache = tail = _hts_cache(opt); cache != NULL; cache = cache->n) {
+ tail = cache;
if (strcmp(cache->iadr, iadr) == 0) { // ok trouvé
- ret = 1;
+ ret = cache->host_length != 0 ? 1 : 0;
break;
}
}
+ // Add empty entry ?
+ if (ret == 2 && add) {
+ assertf(tail != NULL);
+ assertf(tail->n == NULL);
+ if (opt->state.dns_cache_nthreads < 16) {
+ opt->state.dns_cache_nthreads++;
+ tail->n = (t_dnscache *) calloct(1, sizeof(t_dnscache));
+ if (tail->n != NULL) {
+ strcpybuff(tail->n->iadr, iadr);
+ tail->n->host_length = 0; /* pour le moment rien */
+ tail->n->n = NULL;
+ }
+ } else {
+ hts_log_print(opt, LOG_DEBUG, "too many threads, not adding another dns resolution in background");
+ ret = 0;
+ }
+ }
hts_mutexrelease(&opt->state.lock);
return ret;
}