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/15 10:18:21 UTC

[incubator-nuttx-apps] branch master updated: webclient: Add a way to specify timeout

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-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new ce2b951  webclient: Add a way to specify timeout
ce2b951 is described below

commit ce2b9519a7128bea08efe455703a41e34e5016ae
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Tue Jun 15 10:06:17 2021 +0900

    webclient: Add a way to specify timeout
---
 include/netutils/webclient.h   | 8 ++++++++
 netutils/webclient/webclient.c | 5 +++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/netutils/webclient.h b/include/netutils/webclient.h
index 8725d2f..77b7e19 100644
--- a/include/netutils/webclient.h
+++ b/include/netutils/webclient.h
@@ -195,6 +195,13 @@ struct webclient_context
    *   headers          - An array of pointers to the extra headers.
    *   nheaders         - The number of elements in the "headers" array.
    *   bodylen          - The size of the request body.
+   *   timeout_sec      - The timeout in second.
+   *                      This is not meant to cover the entire transaction.
+   *                      Instead, this is meant to be an inactive timer.
+   *                      That is, if no progress is made during the
+   *                      specified amount of time, the operation will fail.
+   *                      The default is CONFIG_WEBCLIENT_TIMEOUT, which is
+   *                      10 seconds by default.
    */
 
   FAR const char *method;
@@ -205,6 +212,7 @@ struct webclient_context
   FAR const char * FAR const *headers;
   unsigned int nheaders;
   size_t bodylen;
+  unsigned int timeout_sec;
 
   /* other parameters
    *
diff --git a/netutils/webclient/webclient.c b/netutils/webclient/webclient.c
index 72f5585..8a64b26 100644
--- a/netutils/webclient/webclient.c
+++ b/netutils/webclient/webclient.c
@@ -815,7 +815,7 @@ int webclient_perform(FAR struct webclient_context *ctx)
 
           snprintf(port_str, sizeof(port_str), "%u", ws->port);
           ret = tls_ops->connect(tls_ctx, ws->hostname, port_str,
-                                 CONFIG_WEBCLIENT_TIMEOUT, &conn.tls_conn);
+                                 ctx->timeout_sec, &conn.tls_conn);
         }
       else
         {
@@ -879,7 +879,7 @@ int webclient_perform(FAR struct webclient_context *ctx)
 
           /* Set send and receive timeout values */
 
-          tv.tv_sec  = CONFIG_WEBCLIENT_TIMEOUT;
+          tv.tv_sec  = ctx->timeout_sec;
           tv.tv_usec = 0;
 
           setsockopt(conn.sockfd, SOL_SOCKET, SO_RCVTIMEO,
@@ -1277,6 +1277,7 @@ void webclient_set_defaults(FAR struct webclient_context *ctx)
 {
   memset(ctx, 0, sizeof(*ctx));
   ctx->method = "GET";
+  ctx->timeout_sec = CONFIG_WEBCLIENT_TIMEOUT;
 }
 
 /****************************************************************************