libs/libc/netdb: add dns clear interface

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-05-24 22:02:44 +08:00 committed by Xiang Xiao
parent 2fd25d7ea7
commit f3a5aee7d7
3 changed files with 43 additions and 0 deletions

View File

@ -224,6 +224,21 @@ void dns_save_answer(FAR const char *hostname,
FAR const union dns_addr_u *addr, int naddr); FAR const union dns_addr_u *addr, int naddr);
#endif #endif
/****************************************************************************
* Name: dns_clear_answer
*
* Description:
* Clear the resolved hostname in the DNS cache
*
* Returned Value:
* None
*
****************************************************************************/
#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0
void dns_clear_answer(void);
#endif
/**************************************************************************** /****************************************************************************
* Name: dns_find_answer * Name: dns_find_answer
* *

View File

@ -270,6 +270,9 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
g_dns_nservers = nservers; g_dns_nservers = nservers;
dns_semgive(); dns_semgive();
#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0
dns_clear_answer();
#endif
dns_notify_nameserver(addr, addrlen); dns_notify_nameserver(addr, addrlen);
return OK; return OK;
} }

View File

@ -164,6 +164,31 @@ void dns_save_answer(FAR const char *hostname,
dns_semgive(); dns_semgive();
} }
/****************************************************************************
* Name: dns_clear_answer
*
* Description:
* Clear the resolved hostname in the DNS cache
*
* Returned Value:
* None
*
****************************************************************************/
void dns_clear_answer(void)
{
/* Get exclusive access to the DNS cache */
dns_semtake();
/* Reset the circular of DNS cache */
g_dns_head = 0;
g_dns_tail = 0;
dns_semgive();
}
/**************************************************************************** /****************************************************************************
* Name: dns_find_answer * Name: dns_find_answer
* *