cURL / Mailing Lists / curl-users / Single Mail

curl-users

[PATCH] make non-blocking stdin optional

From: Eric Wong <normalperson_at_yhbt.net>
Date: Tue, 18 Aug 2009 04:20:19 -0700

My previous change to make stdin non-blocking by default for
"-T-" actually broke existing behavior for some applications.
It could cause the readbusy flag to be permanently set if the
server doesn't send any data while it is reading data from the
client.

This restores previous behavior for "-T-" to not touch the
non-blocking flag for stdin by default (the parent application
can still set it, of course).

Making stdin non-blocking in curl is still possible by
specifying "-T." instead of "-T-". I chose '.' because it is an
impossible name for a regular file.

---
 docs/curl.1 |    3 +++
 src/main.c  |   15 +++++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/docs/curl.1 b/docs/curl.1
index e1bcf5a..ec3e1e0 100644
--- a/docs/curl.1
+++ b/docs/curl.1
@@ -1183,6 +1183,9 @@ file name to use. That will most likely cause the upload operation to fail. If
 this is used on a HTTP(S) server, the PUT command will be used.
 
 Use the file name "-" (a single dash) to use stdin instead of a given file.
+Alternately, the file name "." (a single period) may be specified instead
+of "-" to use stdin in non-blocking mode to allow reading server output
+while stdin is being uploaded.
 
 You can specify one -T for each URL on the command line. Each -T + URL pair
 specifies what to upload and to where. curl also supports "globbing" of the -T
diff --git a/src/main.c b/src/main.c
index 7274940..3bfa735 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3953,6 +3953,10 @@ static void dumpeasycode(struct Configurable *config)
   curl_slist_free_all(easycode);
 }
 
+static bool stdin_upload(const char *uploadfile)
+{
+  return curlx_strequal(uploadfile, "-") || curlx_strequal(uploadfile, ".");
+}
 
 static int
 operate(struct Configurable *config, int argc, argv_item_t argv[])
@@ -4417,7 +4421,7 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
           }
         }
         infdopen=FALSE;
-        if(uploadfile && !curlx_strequal(uploadfile, "-")) {
+        if(uploadfile && !stdin_upload(uploadfile)) {
           /*
            * We have specified a file to upload and it isn't "-".
            */
@@ -4511,11 +4515,14 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
           uploadfilesize=fileinfo.st_size;
 
         }
-        else if(uploadfile && curlx_strequal(uploadfile, "-")) {
+        else if(uploadfile && stdin_upload(uploadfile)) {
           SET_BINMODE(stdin);
           infd = STDIN_FILENO;
-          if (curlx_nonblock((curl_socket_t)infd, TRUE) < 0)
-            warnf(config, "fcntl failed on fd=%d: %s\n", infd, strerror(errno));
+          if (curlx_strequal(uploadfile, ".")) {
+            if (curlx_nonblock((curl_socket_t)infd, TRUE) < 0)
+              warnf(config,
+                    "fcntl failed on fd=%d: %s\n", infd, strerror(errno));
+          }
         }
 
         if(uploadfile && config->resume_from_current)
-- 
Eric Wong
-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2001-09-17