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/01/18 02:44:28 UTC

[incubator-nuttx-apps] 02/02: webclient: Don't call the sink callback if no data is available

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

commit ee1f4fdcdbbfbb02f4e9e9970b27e45a95a724e7
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Thu Jan 14 12:25:05 2021 +0900

    webclient: Don't call the sink callback if no data is available
    
    This happened frequently for me with Docker Desktop's
    /var/run/docker.sock on macOS.
    But I believe it can happen on other environments, even with TCP.
    
    Alternatively, this case can be handled by the callback
    implementations.  But it's simpler to handle the corner case here.
---
 netutils/webclient/webclient.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/netutils/webclient/webclient.c b/netutils/webclient/webclient.c
index 73c18dc..539c7a8 100644
--- a/netutils/webclient/webclient.c
+++ b/netutils/webclient/webclient.c
@@ -982,7 +982,11 @@ int webclient_perform(FAR struct webclient_context *ctx)
                    * received file.
                    */
 
-                  if (ctx->sink_callback)
+                  if (ws->offset == ws->datend)
+                    {
+                      /* We don't have data to give to the client yet. */
+                    }
+                  else if (ctx->sink_callback)
                     {
                       ret = ctx->sink_callback(&ws->buffer, ws->offset,
                                                ws->datend, &ws->buflen,