Skip to content

Commit 12f66be

Browse files
authored
net_http: expire dns lookup failures more quickly (libretro#17481)
1 parent d00ee5a commit 12f66be

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

libretro-common/net/net_http.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ struct dns_cache_entry
138138
static struct dns_cache_entry *dns_cache = NULL;
139139
/* 5 min timeout, in usec */
140140
static const retro_time_t dns_cache_timeout = 1000 /* usec/ms */ * 1000 /* ms/s */ * 60 /* s/min */ * 5 /* min */;
141+
/* only cache failures for 30 seconds */
142+
static const retro_time_t dns_cache_fail_timeout = 1000 /* usec/ms */ * 1000 /* ms/s */ * 30 /* s */;
141143
#ifdef HAVE_THREADS
142144
static slock_t *dns_cache_lock = NULL;
143145
#endif
@@ -690,13 +692,15 @@ static void net_http_dns_cache_remove_expired(void)
690692
struct dns_cache_entry *prev = NULL;
691693
while (entry)
692694
{
693-
if (entry->timestamp + dns_cache_timeout < cpu_features_get_time_usec())
695+
if ( (entry->addr && (entry->timestamp + dns_cache_timeout < cpu_features_get_time_usec()))
696+
|| (!entry->addr && (entry->timestamp + dns_cache_fail_timeout < cpu_features_get_time_usec())))
694697
{
695698
if (prev)
696699
prev->next = entry->next;
697700
else
698701
dns_cache = entry->next;
699-
freeaddrinfo_retro(entry->addr);
702+
if (entry->addr)
703+
freeaddrinfo_retro(entry->addr);
700704
free(entry->domain);
701705
free(entry);
702706
entry = prev ? prev->next : dns_cache;
@@ -720,7 +724,9 @@ static struct dns_cache_entry *net_http_dns_cache_find(const char *domain, int p
720724
{
721725
if (port == entry->port && string_is_equal(entry->domain, domain))
722726
{
723-
entry->timestamp = cpu_features_get_time_usec();
727+
/* don't bump timeestamp for failures */
728+
if (entry->addr)
729+
entry->timestamp = cpu_features_get_time_usec();
724730
return entry;
725731
}
726732
entry = entry->next;

0 commit comments

Comments
 (0)