Skip to content

Commit 20adbf0

Browse files
authored
Merge pull request #7239 from TeroJaasko/let_config_remove_dns_cache_code
netsocket: dns: make dns-cache-size:0 remove whole DNS cache code
2 parents 3ee8f32 + 2e89fa2 commit 20adbf0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

features/netsocket/nsapi_dns.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,15 @@ static nsapi_addr_t dns_servers[DNS_SERVERS_SIZE] = {
111111
0,0, 0,0, 0x1c,0x04, 0xb1,0x2f}},
112112
};
113113

114+
#if (MBED_CONF_NSAPI_DNS_CACHE_SIZE > 0)
114115
static DNS_CACHE *dns_cache[MBED_CONF_NSAPI_DNS_CACHE_SIZE];
116+
// Protects cache shared between blocking and asynchronous calls
117+
static SingletonPtr<PlatformMutex> dns_cache_mutex;
118+
#endif
119+
115120
static uint16_t dns_message_id = 1;
116121
static int dns_unique_id = 1;
117122
static DNS_QUERY *dns_query_queue[DNS_QUERY_QUEUE_SIZE];
118-
// Protects cache shared between blocking and asynchronous calls
119-
static SingletonPtr<PlatformMutex> dns_cache_mutex;
120123
// Protects from several threads running asynchronous DNS
121124
static SingletonPtr<PlatformMutex> dns_mutex;
122125
static SingletonPtr<call_in_callback_cb_t> dns_call_in;
@@ -306,6 +309,7 @@ static int dns_scan_response(const uint8_t *ptr, uint16_t exp_id, uint32_t *ttl,
306309

307310
static void nsapi_dns_cache_add(const char *host, nsapi_addr_t *address, uint32_t ttl)
308311
{
312+
#if (MBED_CONF_NSAPI_DNS_CACHE_SIZE > 0)
309313
// RFC 1034: if TTL is zero, entry is not added to cache
310314
if (ttl == 0) {
311315
return;
@@ -354,12 +358,14 @@ static void nsapi_dns_cache_add(const char *host, nsapi_addr_t *address, uint32_
354358
}
355359

356360
dns_cache_mutex->unlock();
361+
#endif
357362
}
358363

359364
static nsapi_error_t nsapi_dns_cache_find(const char *host, nsapi_version_t version, nsapi_addr_t *address)
360365
{
361366
nsapi_error_t ret_val = NSAPI_ERROR_NO_ADDRESS;
362367

368+
#if (MBED_CONF_NSAPI_DNS_CACHE_SIZE > 0)
363369
dns_cache_mutex->lock();
364370

365371
for (int i = 0; i < MBED_CONF_NSAPI_DNS_CACHE_SIZE; i++) {
@@ -382,6 +388,7 @@ static nsapi_error_t nsapi_dns_cache_find(const char *host, nsapi_version_t vers
382388
}
383389

384390
dns_cache_mutex->unlock();
391+
#endif
385392

386393
return ret_val;
387394
}

0 commit comments

Comments
 (0)