mirror of https://github.com/ARMmbed/mbed-os.git
DNS manual cleanup mechanism added
parent
d0b5ba6d84
commit
6adc2440a3
|
@ -32,6 +32,7 @@ int result_exp_timeout;
|
|||
|
||||
void ASYNCHRONOUS_DNS()
|
||||
{
|
||||
nsapi_dns_reset();
|
||||
do_asynchronous_gethostbyname(dns_test_hosts, 1, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
|
||||
|
||||
TEST_ASSERT_EQUAL(1, result_ok);
|
||||
|
|
|
@ -41,6 +41,8 @@ void ASYNCHRONOUS_DNS_CACHE()
|
|||
Ticker ticker;
|
||||
ticker.attach_us(&test_dns_query_ticker, 100);
|
||||
|
||||
nsapi_dns_reset();
|
||||
|
||||
for (unsigned int i = 0; i < 5; i++) {
|
||||
int started_us = ticker_us;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ void ASYNCHRONOUS_DNS_CANCEL()
|
|||
dns_application_data *data = new dns_application_data[MBED_CONF_APP_DNS_TEST_HOSTS_NUM];
|
||||
|
||||
int count = 0;
|
||||
nsapi_dns_reset();
|
||||
|
||||
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
|
||||
data[i].value_set = false;
|
||||
|
|
|
@ -54,6 +54,7 @@ static nsapi_error_t event_queue_call(int delay, mbed::Callback<void()> func)
|
|||
void ASYNCHRONOUS_DNS_EXTERNAL_EVENT_QUEUE()
|
||||
{
|
||||
// Ensures that cache does not contain entries
|
||||
nsapi_dns_reset();
|
||||
do_asynchronous_gethostbyname(dns_test_hosts, MBED_CONF_NSAPI_DNS_CACHE_SIZE, &result_ok, &result_no_mem,
|
||||
&result_dns_failure, &result_exp_timeout);
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ int result_exp_timeout;
|
|||
void ASYNCHRONOUS_DNS_INVALID_HOST()
|
||||
{
|
||||
// Ensures that cache does not contain entries
|
||||
nsapi_dns_reset();
|
||||
do_asynchronous_gethostbyname(dns_test_hosts_second, MBED_CONF_NSAPI_DNS_CACHE_SIZE, &result_ok, &result_no_mem,
|
||||
&result_dns_failure, &result_exp_timeout);
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ void ASYNCHRONOUS_DNS_NON_ASYNC_AND_ASYNC()
|
|||
dns_application_data data;
|
||||
data.semaphore = &semaphore;
|
||||
|
||||
nsapi_dns_reset();
|
||||
|
||||
// Initiate
|
||||
nsapi_error_t err = get_interface()->gethostbyname_async(dns_test_hosts_second[0],
|
||||
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data));
|
||||
|
|
|
@ -32,6 +32,7 @@ int result_exp_timeout;
|
|||
|
||||
void ASYNCHRONOUS_DNS_SIMULTANEOUS()
|
||||
{
|
||||
nsapi_dns_reset();
|
||||
do_asynchronous_gethostbyname(dns_test_hosts_second, MBED_CONF_APP_DNS_SIMULT_QUERIES + 1, &result_ok, &result_no_mem,
|
||||
&result_dns_failure, &result_exp_timeout);
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ int result_exp_timeout;
|
|||
|
||||
void ASYNCHRONOUS_DNS_SIMULTANEOUS_CACHE()
|
||||
{
|
||||
nsapi_dns_reset();
|
||||
do_asynchronous_gethostbyname(dns_test_hosts_second, MBED_CONF_APP_DNS_SIMULT_QUERIES + 1, &result_ok, &result_no_mem,
|
||||
&result_dns_failure, &result_exp_timeout);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ int result_exp_timeout;
|
|||
|
||||
void ASYNCHRONOUS_DNS_SIMULTANEOUS_REPEAT()
|
||||
{
|
||||
|
||||
nsapi_dns_reset();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
do_asynchronous_gethostbyname(dns_test_hosts, MBED_CONF_APP_DNS_SIMULT_QUERIES + 1, &result_ok, &result_no_mem,
|
||||
&result_dns_failure, &result_exp_timeout);
|
||||
|
|
|
@ -50,6 +50,7 @@ static nsapi_error_t event_queue_call(int delay, mbed::Callback<void()> func)
|
|||
void ASYNCHRONOUS_DNS_TIMEOUTS()
|
||||
{
|
||||
// Ensures that cache does not contain entries
|
||||
nsapi_dns_reset();
|
||||
do_asynchronous_gethostbyname(dns_test_hosts, MBED_CONF_NSAPI_DNS_CACHE_SIZE, &result_ok, &result_no_mem,
|
||||
&result_dns_failure, &result_exp_timeout);
|
||||
|
||||
|
|
|
@ -155,6 +155,7 @@ NetworkInterface *get_interface()
|
|||
|
||||
static void net_bringup()
|
||||
{
|
||||
nsapi_dns_reset();
|
||||
MBED_ASSERT(MBED_CONF_APP_DNS_TEST_HOSTS_NUM >= MBED_CONF_NSAPI_DNS_CACHE_SIZE && MBED_CONF_APP_DNS_TEST_HOSTS_NUM >= MBED_CONF_APP_DNS_SIMULT_QUERIES + 1);
|
||||
|
||||
net = NetworkInterface::get_default_instance();
|
||||
|
|
|
@ -32,6 +32,7 @@ int result_exp_timeout;
|
|||
|
||||
void SYNCHRONOUS_DNS()
|
||||
{
|
||||
nsapi_dns_reset();
|
||||
do_gethostbyname(dns_test_hosts, 1, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
|
||||
|
||||
TEST_ASSERT_EQUAL(1, result_ok);
|
||||
|
|
|
@ -34,6 +34,7 @@ static void test_dns_query_ticker(void)
|
|||
|
||||
void SYNCHRONOUS_DNS_CACHE()
|
||||
{
|
||||
nsapi_dns_reset();
|
||||
Ticker ticker;
|
||||
ticker.attach_us(&test_dns_query_ticker, 100);
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ int result_exp_timeout;
|
|||
void SYNCHRONOUS_DNS_INVALID()
|
||||
{
|
||||
//Ensure that there are no addressess in cache
|
||||
nsapi_dns_reset();
|
||||
do_gethostbyname(dns_test_hosts_second, MBED_CONF_NSAPI_DNS_CACHE_SIZE, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
|
||||
|
||||
char dns_test_hosts_new[MBED_CONF_APP_DNS_TEST_HOSTS_NUM][DNS_TEST_HOST_LEN];
|
||||
|
|
|
@ -32,6 +32,7 @@ int result_exp_timeout;
|
|||
|
||||
void SYNCHRONOUS_DNS_MULTIPLE()
|
||||
{
|
||||
nsapi_dns_reset();
|
||||
do_gethostbyname(dns_test_hosts, MBED_CONF_APP_DNS_TEST_HOSTS_NUM, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
|
||||
|
||||
TEST_ASSERT_EQUAL(MBED_CONF_APP_DNS_TEST_HOSTS_NUM, result_ok);
|
||||
|
|
|
@ -51,7 +51,7 @@ void MULTIHOMING_ASYNCHRONOUS_DNS()
|
|||
dns_application_data data;
|
||||
data.semaphore = &semaphore;
|
||||
|
||||
|
||||
nsapi_dns_reset();
|
||||
|
||||
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ void MULTIHOMING_SYNCHRONOUS_DNS()
|
|||
result_dns_failure = 0;
|
||||
result_exp_timeout = 0;
|
||||
|
||||
nsapi_dns_reset();
|
||||
|
||||
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
|
||||
SocketAddress address;
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ static void _sigio_handler(osThreadId id)
|
|||
|
||||
void MULTIHOMING_UDPSOCKET_ECHOTEST()
|
||||
{
|
||||
nsapi_dns_reset();
|
||||
|
||||
for (unsigned int interface_index = 0; interface_index < MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM; interface_index++) {
|
||||
NetworkInterface *interface = get_interface(interface_index);
|
||||
|
|
|
@ -46,3 +46,8 @@ extern "C" nsapi_error_t nsapi_dns_add_server(nsapi_addr_t addr, const char *int
|
|||
{
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
void nsapi_dns_cache_reset()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ struct DNS_QUERY {
|
|||
|
||||
static void nsapi_dns_cache_add(const char *host, nsapi_addr_t *address, uint32_t ttl);
|
||||
static nsapi_size_or_error_t nsapi_dns_cache_find(const char *host, nsapi_version_t version, nsapi_addr_t *address);
|
||||
static void nsapi_dns_cache_reset();
|
||||
|
||||
static nsapi_error_t nsapi_dns_get_server_addr(NetworkStack *stack, uint8_t *index, uint8_t *total_attempts, uint8_t *send_success, SocketAddress *dns_addr, const char *interface_name);
|
||||
|
||||
|
@ -403,6 +404,22 @@ static nsapi_error_t nsapi_dns_cache_find(const char *host, nsapi_version_t vers
|
|||
return ret_val;
|
||||
}
|
||||
|
||||
static void nsapi_dns_cache_reset()
|
||||
{
|
||||
#if (MBED_CONF_NSAPI_DNS_CACHE_SIZE > 0)
|
||||
dns_cache_mutex->lock();
|
||||
for (int i = 0; i < MBED_CONF_NSAPI_DNS_CACHE_SIZE; i++) {
|
||||
if (dns_cache[i]) {
|
||||
delete dns_cache[i]->host;
|
||||
dns_cache[i]->host = NULL;
|
||||
delete dns_cache[i];
|
||||
dns_cache[i] = NULL;
|
||||
}
|
||||
}
|
||||
dns_cache_mutex->unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
static nsapi_error_t nsapi_dns_get_server_addr(NetworkStack *stack, uint8_t *index, uint8_t *total_attempts, uint8_t *send_success, SocketAddress *dns_addr, const char *interface_name)
|
||||
{
|
||||
bool dns_addr_set = false;
|
||||
|
@ -618,6 +635,11 @@ void nsapi_dns_call_in_set(call_in_callback_cb_t callback)
|
|||
*dns_call_in.get() = callback;
|
||||
}
|
||||
|
||||
void nsapi_dns_reset()
|
||||
{
|
||||
nsapi_dns_cache_reset();
|
||||
}
|
||||
|
||||
nsapi_error_t nsapi_dns_call_in(call_in_callback_cb_t cb, int delay, mbed::Callback<void()> func)
|
||||
{
|
||||
if (*dns_call_in.get()) {
|
||||
|
|
|
@ -228,6 +228,14 @@ nsapi_error_t nsapi_dns_query_async_cancel(nsapi_error_t id);
|
|||
*/
|
||||
void nsapi_dns_call_in_set(call_in_callback_cb_t callback);
|
||||
|
||||
/**
|
||||
* @brief nsapi_dns_reset Resets all internal states and frees reserved memory, see NOTE!
|
||||
* Can be used to clean up system resources when there is no need for network connections.
|
||||
* NOTE: Does NOT clear asynchronous ongoing operations!
|
||||
* Currently only cleans up DNS cache (if used)
|
||||
*/
|
||||
void nsapi_dns_reset();
|
||||
|
||||
/** Add a domain name server to list of servers to query
|
||||
*
|
||||
* @param addr Destination for the host address
|
||||
|
|
Loading…
Reference in New Issue