xiaoxiang781216 commented on code in PR #21126:
URL: https://github.com/apache/nuttx/pull/21126#discussion_r4419610574


##########
libs/libc/netdb/lib_resinit.c:
##########
@@ -49,5 +69,61 @@
 
 int res_init(void)
 {
+  FAR struct __res_state *res = __res_state();
+
+  /* The defaults of BIND for the fields that the program did not set.
+   * NuttX's resolver does not use them.
+   */
+
+  if (res->retrans == 0)
+    {
+      res->retrans = RES_TIMEOUT;
+    }
+
+  if (res->retry == 0)
+    {
+      res->retry = RES_DFLRETRY;
+    }
+
+  if ((res->options & RES_INIT) == 0)
+    {
+      res->options = RES_DEFAULT;
+      res->ndots = 1;
+    }
+
+  res->options |= RES_INIT;
   return 0;
 }
+
+/****************************************************************************
+ * Name: __res_state
+ *
+ * Description:
+ *   Give the resolver state of the process (the _res of <resolv.h>).  In
+ *   the FLAT and PROTECTED builds it is the state of the task group,
+ *   which is allocated at the first call.
+ *
+ ****************************************************************************/
+
+FAR struct __res_state *__res_state(void)
+{
+#ifndef CONFIG_BUILD_KERNEL
+  FAR struct task_info_s *info = task_get_info();
+  FAR struct __res_state *res;
+
+  DEBUGASSERT(info != NULL);
+
+  nxrmutex_lock(&info->ta_lock);
+  if (info->ta_res == NULL)
+    {
+      info->ta_res = lib_zalloc(sizeof(struct __res_state));
+    }
+
+  res = info->ta_res;
+  nxrmutex_unlock(&info->ta_lock);
+
+  return res != NULL ? res : &g_res;
+#else
+  return &g_res;

Review Comment:
   can we share the same code path for the different  mode



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to