You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/11/26 08:27:44 UTC

[GitHub] [incubator-nuttx-apps] coffee809721232 opened a new pull request #904: netutils/dhcpc: add non-blocking interface

coffee809721232 opened a new pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904


   ## Summary
   netutils/dhcpc: add non-blocking interface
   
   Signed-off-by: songlinzhang <so...@xiaomi.com>
   ## Impact
   Add dhcpc_request_async function
   ## Testing
   Replace dhcpc_request
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] coffee809721232 commented on pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
coffee809721232 commented on pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#issuecomment-1005475381


   > Was there a plan to update `netinit_net_bringup` to use `dhcpc_request_async`? and/or add some built-in commands like `ntpc` has to start/stop a dhcpc daemon?
   Plan to add commands to start and stop the dhcpc daemon
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] hartmannathan commented on pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
hartmannathan commented on pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#issuecomment-981720272


   Looks like I'm late to the party but LGTM.
   
   Just one question:
   
   Are we sure we want to remove the typecast from the (void *) returned by malloc() to (FAR struct dhcpc_state_s *) in this call:
   
   ```
   -pdhcpc = (FAR struct dhcpc_state_s *)malloc(sizeof(struct dhcpc_state_s));
   +pdhcpc = malloc(sizeof(struct dhcpc_state_s) + maclen - 1);
   ```
   
   Some compilers may warn about that.
   
   Might also benefit from a comment explaining the `maclen - 1` such as:
   
   ```
   /* maclen - 1: First byte of maclen is included in the structure */
   ```
   
   So that someone in the future won't think it's a mistake.


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] coffee809721232 commented on a change in pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
coffee809721232 commented on a change in pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#discussion_r778506925



##########
File path: netutils/dhcpc/dhcpc.c
##########
@@ -445,6 +448,47 @@ static uint8_t dhcpc_parsemsg(FAR struct dhcpc_state_s *pdhcpc, int buflen,
   return 0;
 }
 
+/****************************************************************************
+ * Name: dhcpc_run
+ ****************************************************************************/
+
+static void *dhcpc_run(void *args)
+{
+  FAR struct dhcpc_state_s *pdhcpc = (FAR struct dhcpc_state_s *)args;
+  struct dhcpc_state result;
+  int ret;
+
+  while (1)
+    {
+      ret = dhcpc_request(pdhcpc, &result);
+      if (ret == OK)
+        {
+          pdhcpc->callback(&result);
+        }
+      else
+        {
+          pdhcpc->callback(NULL);
+          nerr("dhcpc_request error\n");
+        }
+
+      if (pdhcpc->cancel)
+        {
+          return NULL;
+        }
+
+      while (result.lease_time)
+        {
+          result.lease_time = sleep(result.lease_time);

Review comment:
       > Note: This should only sleep half of the lease_time before renewing.
   
   Yes, it should be half of the time to re-request.
   This bug will be fixed later.
   thanks. @normanr @xiaoxiang781216 




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] hartmannathan commented on pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
hartmannathan commented on pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#issuecomment-981770040


   > > Are we sure we want to remove the typecast from the (void *) returned by malloc() to (FAR struct dhcpc_state_s *) in this call:
   > > ```
   > > -pdhcpc = (FAR struct dhcpc_state_s *)malloc(sizeof(struct dhcpc_state_s));
   > > +pdhcpc = malloc(sizeof(struct dhcpc_state_s) + maclen - 1);
   > > ```
   > 
   > It's a normal practice to let compiler auto convert void * to type * in C: https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc
   > 
   > > Some compilers may warn about that.
   > 
   > This implicit conversion is allowed by C standard. But, it forbid by C++.
   
   Ah yes, that's what it is. In my own work I code C so it builds as both C and C++, so I forgot that's a C++ warning. Here I guess it's okay since we are coding for C89.
   
   Thanks!


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#issuecomment-1005056486


   Nice idea, @coffee809721232 please take a look.


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] coffee809721232 edited a comment on pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
coffee809721232 edited a comment on pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#issuecomment-1005475381


   > Was there a plan to update `netinit_net_bringup` to use `dhcpc_request_async`? and/or add some built-in commands like `ntpc` has to start/stop a dhcpc daemon?
   Plan to add commands to start and stop the dhcpc daemon


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] hartmannathan commented on a change in pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
hartmannathan commented on a change in pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#discussion_r757532966



##########
File path: netutils/dhcpc/dhcpc.c
##########
@@ -475,8 +520,8 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
 
       memset(pdhcpc, 0, sizeof(struct dhcpc_state_s));
       pdhcpc->interface  = interface;
-      pdhcpc->ds_macaddr = macaddr;
-      pdhcpc->ds_maclen  = maclen;
+      pdhcpc->ds_maclen  = maclen > IFHWADDRLEN ? IFHWADDRLEN : maclen;

Review comment:
       If `maclen` too large, should we return error status (NULL) instead of proceeding?




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#issuecomment-981732099


   > Looks like I'm late to the party but LGTM.
   > 
   > Just one question:
   > 
   > Are we sure we want to remove the typecast from the (void *) returned by malloc() to (FAR struct dhcpc_state_s *) in this call:
   > 
   > ```
   > -pdhcpc = (FAR struct dhcpc_state_s *)malloc(sizeof(struct dhcpc_state_s));
   > +pdhcpc = malloc(sizeof(struct dhcpc_state_s) + maclen - 1);
   > ```
   > 
   
   It's a normal practice to let compiler auto convert void * to type * in C:
   https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc
   
   > Some compilers may warn about that.
   > 
   
   This implicit conversion is allowed by C standard. But, it forbid by C++.
   
   
   > Might also benefit from a comment explaining the `maclen - 1` such as:
   > 
   > ```
   > /* maclen - 1: First byte of maclen is included in the structure */
   > ```
   > 
   > So that someone in the future won't think it's a mistake.
   
   Yes, good suggestion.


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] xiaoxiang781216 merged pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904


   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] normanr commented on pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
normanr commented on pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#issuecomment-1002316922


   Was there a plan to update `netinit_net_bringup` to use `dhcpc_request_async`? and/or add some built-in commands like `ntpc` has to start/stop a dhcpc daemon?


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] coffee809721232 commented on a change in pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
coffee809721232 commented on a change in pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#discussion_r758063137



##########
File path: netutils/dhcpc/dhcpc.c
##########
@@ -475,8 +520,8 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
 
       memset(pdhcpc, 0, sizeof(struct dhcpc_state_s));
       pdhcpc->interface  = interface;
-      pdhcpc->ds_macaddr = macaddr;
-      pdhcpc->ds_maclen  = maclen;
+      pdhcpc->ds_maclen  = maclen > IFHWADDRLEN ? IFHWADDRLEN : maclen;

Review comment:
       I adjusted the storage method of mac address, please review.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on a change in pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#discussion_r778290829



##########
File path: netutils/dhcpc/dhcpc.c
##########
@@ -445,6 +448,47 @@ static uint8_t dhcpc_parsemsg(FAR struct dhcpc_state_s *pdhcpc, int buflen,
   return 0;
 }
 
+/****************************************************************************
+ * Name: dhcpc_run
+ ****************************************************************************/
+
+static void *dhcpc_run(void *args)
+{
+  FAR struct dhcpc_state_s *pdhcpc = (FAR struct dhcpc_state_s *)args;
+  struct dhcpc_state result;
+  int ret;
+
+  while (1)
+    {
+      ret = dhcpc_request(pdhcpc, &result);
+      if (ret == OK)
+        {
+          pdhcpc->callback(&result);
+        }
+      else
+        {
+          pdhcpc->callback(NULL);
+          nerr("dhcpc_request error\n");
+        }
+
+      if (pdhcpc->cancel)
+        {
+          return NULL;
+        }
+
+      while (result.lease_time)
+        {
+          result.lease_time = sleep(result.lease_time);

Review comment:
       @coffee809721232 




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] normanr commented on a change in pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
normanr commented on a change in pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#discussion_r776099915



##########
File path: netutils/dhcpc/dhcpc.c
##########
@@ -445,6 +448,47 @@ static uint8_t dhcpc_parsemsg(FAR struct dhcpc_state_s *pdhcpc, int buflen,
   return 0;
 }
 
+/****************************************************************************
+ * Name: dhcpc_run
+ ****************************************************************************/
+
+static void *dhcpc_run(void *args)
+{
+  FAR struct dhcpc_state_s *pdhcpc = (FAR struct dhcpc_state_s *)args;
+  struct dhcpc_state result;
+  int ret;
+
+  while (1)
+    {
+      ret = dhcpc_request(pdhcpc, &result);
+      if (ret == OK)
+        {
+          pdhcpc->callback(&result);
+        }
+      else
+        {
+          pdhcpc->callback(NULL);
+          nerr("dhcpc_request error\n");
+        }
+
+      if (pdhcpc->cancel)
+        {
+          return NULL;
+        }
+
+      while (result.lease_time)
+        {
+          result.lease_time = sleep(result.lease_time);

Review comment:
       Note: This should only sleep half of the lease_time before renewing.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on a change in pull request #904: netutils/dhcpc: add non-blocking interface

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #904:
URL: https://github.com/apache/incubator-nuttx-apps/pull/904#discussion_r758027697



##########
File path: netutils/dhcpc/dhcpc.c
##########
@@ -468,15 +512,15 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
 
   /* Allocate an internal DHCP structure */
 
-  pdhcpc = (FAR struct dhcpc_state_s *)malloc(sizeof(struct dhcpc_state_s));
+  pdhcpc = malloc(sizeof(struct dhcpc_state_s) + maclen + 1);

Review comment:
       change + 1 to - 1




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org