]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: fix --upload-file . hangs if delay in STDIN
authorJohn Schroeder <john@schroederspace.com>
Tue, 26 Nov 2019 08:16:19 +0000 (09:16 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 26 Nov 2019 08:17:52 +0000 (09:17 +0100)
Attempt to unpause a busy read in the CURLOPT_XFERINFOFUNCTION.

When uploading from stdin in non-blocking mode, a delay in reading
the stream (EAGAIN) causes curl to pause sending data
(CURL_READFUNC_PAUSE).  Prior to this change, a busy read was
detected and unpaused only in the CURLOPT_WRITEFUNCTION handler.
This change performs the same busy read handling in a
CURLOPT_XFERINFOFUNCTION handler.

Fixes #2051
Closes #4599
Reported-by: bdry on github
src/tool_cb_prg.c
src/tool_cb_rea.c
src/tool_cb_rea.h
src/tool_operate.c
src/tool_operate.h
src/tool_progress.c

index a18827c8bf5cd2316a4e0b04a4c4d1fee153362c..505ae751f618b212a84c7ff24b616719aebbc017 100644 (file)
@@ -32,6 +32,7 @@
 #include "tool_cfgable.h"
 #include "tool_cb_prg.h"
 #include "tool_util.h"
+#include "tool_operate.h"
 
 #include "memdebug.h" /* keep this as LAST include */
 
@@ -121,7 +122,10 @@ int tool_progress_cb(void *clientp,
      and this new edition inherits some of his concepts. */
 
   struct timeval now = tvnow();
-  struct ProgressData *bar = (struct ProgressData *)clientp;
+  struct per_transfer *per = clientp;
+  struct OutStruct *outs = &per->outs;
+  struct OperationConfig *config = outs->config;
+  struct ProgressData *bar = &per->progressbar;
   curl_off_t total;
   curl_off_t point;
 
@@ -191,6 +195,11 @@ int tool_progress_cb(void *clientp,
   bar->prev = point;
   bar->prevtime = now;
 
+  if(config->readbusy) {
+    config->readbusy = FALSE;
+    curl_easy_pause(per->curl, CURLPAUSE_CONT);
+  }
+
   return 0;
 }
 
index 06f60eca7cc543ead7c0a9602ab0d998a8f93c14..03ed4a4671a77827211e400a61adc1e26a311bb8 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "tool_cfgable.h"
 #include "tool_cb_rea.h"
+#include "tool_operate.h"
 
 #include "memdebug.h" /* keep this as LAST include */
 
@@ -52,3 +53,28 @@ size_t tool_read_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
   in->config->readbusy = FALSE;
   return (size_t)rc;
 }
+
+/*
+** callback for CURLOPT_XFERINFOFUNCTION used to unpause busy reads
+*/
+
+int tool_readbusy_cb(void *clientp,
+                     curl_off_t dltotal, curl_off_t dlnow,
+                     curl_off_t ultotal, curl_off_t ulnow)
+{
+  struct per_transfer *per = clientp;
+  struct OutStruct *outs = &per->outs;
+  struct OperationConfig *config = outs->config;
+
+  (void)dltotal;  /* unused */
+  (void)dlnow;  /* unused */
+  (void)ultotal;  /* unused */
+  (void)ulnow;  /* unused */
+
+  if(config->readbusy) {
+    config->readbusy = FALSE;
+    curl_easy_pause(per->curl, CURLPAUSE_CONT);
+  }
+
+  return per->noprogress? 0 : CURL_PROGRESSFUNC_CONTINUE;
+}
index fe744e8f7d612899cada28ec5f8a2e43d2a9f80e..5f7e483a30fbe4229a545b7dc8c51da644451ccc 100644 (file)
 
 size_t tool_read_cb(void *buffer, size_t sz, size_t nmemb, void *userdata);
 
+/*
+** callback for CURLOPT_XFERINFOFUNCTION used to unpause busy reads
+*/
+
+int tool_readbusy_cb(void *clientp,
+                     curl_off_t dltotal, curl_off_t dlnow,
+                     curl_off_t ultotal, curl_off_t ulnow);
+
 #endif /* HEADER_CURL_TOOL_CB_REA_H */
index 0de81cd49b2a2b6240a2b4726653bdfffa276e9f..4b2ffb55bf6ef8d8d444dfa7819f98c629f03c5d 100644 (file)
@@ -1080,11 +1080,11 @@ static CURLcode single_transfer(struct GlobalConfig *global,
            isatty(fileno(outs->stream)))
           /* we send the output to a tty, therefore we switch off the progress
              meter */
-          global->noprogress = global->isatty = TRUE;
+          per->noprogress = global->noprogress = global->isatty = TRUE;
         else {
           /* progress meter is per download, so restore config
              values */
-          global->noprogress = orig_noprogress;
+          per->noprogress = global->noprogress = orig_noprogress;
           global->isatty = orig_isatty;
         }
 
@@ -1573,7 +1573,14 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           /* we want the alternative style, then we have to implement it
              ourselves! */
           my_setopt(curl, CURLOPT_XFERINFOFUNCTION, tool_progress_cb);
-          my_setopt(curl, CURLOPT_XFERINFODATA, &per->progressbar);
+          my_setopt(curl, CURLOPT_XFERINFODATA, per);
+        }
+        else if(per->uploadfile && !strcmp(per->uploadfile, ".")) {
+          /* when reading from stdin in non-blocking mode, we use the progress
+             function to unpause a busy read */
+          my_setopt(curl, CURLOPT_NOPROGRESS, 0L);
+          my_setopt(curl, CURLOPT_XFERINFOFUNCTION, tool_readbusy_cb);
+          my_setopt(curl, CURLOPT_XFERINFODATA, per);
         }
 
         /* new in libcurl 7.24.0: */
index 60257fc602b508dfe59bfa4b3f67272881060824..7223db76714127d41c3ee127d6917df32003b9d6 100644 (file)
@@ -44,6 +44,7 @@ struct per_transfer {
   char *outfile;
   bool infdopen; /* TRUE if infd needs closing */
   int infd;
+  bool noprogress;
   struct ProgressData progressbar;
   struct OutStruct outs;
   struct OutStruct heads;
index a2667f38e79246c66fc687c0487f76753af1ec1a..ac4f58f415484a14903bc44a174327824e6eaf4f 100644 (file)
@@ -95,10 +95,18 @@ int xferinfo_cb(void *clientp,
                 curl_off_t ulnow)
 {
   struct per_transfer *per = clientp;
+  struct OutStruct *outs = &per->outs;
+  struct OperationConfig *config = outs->config;
   per->dltotal = dltotal;
   per->dlnow = dlnow;
   per->ultotal = ultotal;
   per->ulnow = ulnow;
+
+  if(config->readbusy) {
+    config->readbusy = FALSE;
+    curl_easy_pause(per->curl, CURLPAUSE_CONT);
+  }
+
   return 0;
 }