You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/06/11 09:54:40 UTC

[incubator-nuttx] branch master updated: libs/libc/netdb: add dns clear interface

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new f3a5aee  libs/libc/netdb: add dns clear interface
f3a5aee is described below

commit f3a5aee7d7a5234c726c7bd066c79592f4128f62
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon May 24 22:02:44 2021 +0800

    libs/libc/netdb: add dns clear interface
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 libs/libc/netdb/lib_dns.h          | 15 +++++++++++++++
 libs/libc/netdb/lib_dnsaddserver.c |  3 +++
 libs/libc/netdb/lib_dnscache.c     | 25 +++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/libs/libc/netdb/lib_dns.h b/libs/libc/netdb/lib_dns.h
index 95e2dcc..3ee8aee 100644
--- a/libs/libc/netdb/lib_dns.h
+++ b/libs/libc/netdb/lib_dns.h
@@ -225,6 +225,21 @@ void dns_save_answer(FAR const char *hostname,
 #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
  *
  * Description:
diff --git a/libs/libc/netdb/lib_dnsaddserver.c b/libs/libc/netdb/lib_dnsaddserver.c
index bcbc7ab..20dc389 100644
--- a/libs/libc/netdb/lib_dnsaddserver.c
+++ b/libs/libc/netdb/lib_dnsaddserver.c
@@ -270,6 +270,9 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
 
   g_dns_nservers = nservers;
   dns_semgive();
+#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0
+  dns_clear_answer();
+#endif
   dns_notify_nameserver(addr, addrlen);
   return OK;
 }
diff --git a/libs/libc/netdb/lib_dnscache.c b/libs/libc/netdb/lib_dnscache.c
index d4ba396..5f2ccaf 100644
--- a/libs/libc/netdb/lib_dnscache.c
+++ b/libs/libc/netdb/lib_dnscache.c
@@ -165,6 +165,31 @@ void dns_save_answer(FAR const char *hostname,
 }
 
 /****************************************************************************
+ * 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
  *
  * Description: