Hello everyone,

I propose the following patch to src/tool_operate.c in order to add
Windows support for file-uploads using stdin, especially for
interoperability with the custom stdin handling in lib/telnet.c.

It would be great if you guys could run your test suites on other
platforms with this patch. This would also fix test case 1326 getting
stuck on Windows.

An alternative solution would be to add Windows stdin handling to the
custom read function in src/tool_cb_rea.c, but that probably will not be
easy.

Actually I wonder why the current implementation works on Linux, since
the non-Windows implementation in lib/telnet.c also does not handle
end-of-file if a custom read function is used.

Best regards,
Marc
From 86cdc842cf0b99dc2e4484f2e6ddebfc01961aec Mon Sep 17 00:00:00 2001
From: Marc Hoersken <[email protected]>
Date: Wed, 16 Dec 2015 16:23:59 +0100
Subject: [PATCH] tool_operate.c: add Windows support for file-uploads using
 stdin

The custom read callback function used by the curl tool does not
terminate if a file is read using stdin-redirection (<file).

Therefore it should only be used for non-stdin file-based uploads.
---
 src/tool_operate.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/tool_operate.c b/src/tool_operate.c
index 30d60cb..d383b4c 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -821,10 +821,22 @@ static CURLcode operate_do(struct GlobalConfig *global,
          * The circumstances in which it is preferable to enable this
          * behaviour, by omitting to set the READFUNCTION & READDATA options,
          * have not been determined.
+         *
+         * Update on 2015-12-16 by Marc Hoersken:
+         *
+         * The READFUNCTION does not support reading files using stdin on
+         * Windows for lib/telnet.c, because it will block by reading forever.
+         * Therefore the READFUNCTION is only used for non-stdin uploads.
          */
-        my_setopt(curl, CURLOPT_READDATA, &input);
-        /* what call to read */
-        my_setopt(curl, CURLOPT_READFUNCTION, tool_read_cb);
+#if defined(MSDOS) || defined(WIN32)
+        if(infdopen) {
+#endif /* MSDOS || WIN32 */
+          my_setopt(curl, CURLOPT_READDATA, &input);
+          /* what call to read */
+          my_setopt(curl, CURLOPT_READFUNCTION, tool_read_cb);
+#if defined(MSDOS) || defined(WIN32)
+        }
+#endif /* MSDOS || WIN32 */
 
         /* in 7.18.0, the CURLOPT_SEEKFUNCTION/DATA pair is taking over what
            CURLOPT_IOCTLFUNCTION/DATA pair previously provided for seeking */
-- 
2.6.3.windows.1

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to