9d7d3f
From f9ebe8047f5f62dfcee379b010d8207f0d6985b1 Mon Sep 17 00:00:00 2001
9d7d3f
From: Daniel Stenberg <daniel@haxx.se>
9d7d3f
Date: Mon, 3 Jun 2013 20:19:51 +0200
9d7d3f
Subject: [PATCH 1/5] curl_multi_wait: reduce timeout if the multi handle wants
9d7d3f
 to
9d7d3f
9d7d3f
If the multi handle's pending timeout is less than what is passed into
9d7d3f
this function, it will now opt to use the shorter time anyway since it
9d7d3f
is a very good hint that the handle wants to process something in a
9d7d3f
shorter time than what otherwise would happen.
9d7d3f
9d7d3f
curl_multi_wait.3 was updated accordingly to clarify
9d7d3f
9d7d3f
This is the reason for bug #1224
9d7d3f
9d7d3f
Bug: http://curl.haxx.se/bug/view.cgi?id=1224
9d7d3f
Reported-by: Andrii Moiseiev
9d7d3f
9d7d3f
Upstream-commit: 29bf0598aad58d9da5dd8c5358f5175dae49026d
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 docs/libcurl/curl_multi_wait.3 | 3 +++
9d7d3f
 lib/multi.c                    | 9 +++++++++
9d7d3f
 2 files changed, 12 insertions(+)
9d7d3f
9d7d3f
diff --git a/docs/libcurl/curl_multi_wait.3 b/docs/libcurl/curl_multi_wait.3
9d7d3f
index b14760b..57c40f0 100644
9d7d3f
--- a/docs/libcurl/curl_multi_wait.3
9d7d3f
+++ b/docs/libcurl/curl_multi_wait.3
9d7d3f
@@ -36,6 +36,9 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
9d7d3f
 This function polls on all file descriptors used by the curl easy handles
9d7d3f
 contained in the given multi handle set.  It will block until activity is
9d7d3f
 detected on at least one of the handles or \fItimeout_ms\fP has passed.
9d7d3f
+Alternatively, if the multi handle has a pending internal timeout that has a
9d7d3f
+shorter expiry time than \fItimeout_ms\fP, that shorter time will be used
9d7d3f
+instead to make sure timeout accuracy is reasonably kept.
9d7d3f
 
9d7d3f
 The calling application may pass additional curl_waitfd structures which are
9d7d3f
 similar to \fIpoll(2)\fP's pollfd structure to be waited on in the same call.
9d7d3f
diff --git a/lib/multi.c b/lib/multi.c
9d7d3f
index 9a8e68e..c8dd97d 100644
9d7d3f
--- a/lib/multi.c
9d7d3f
+++ b/lib/multi.c
9d7d3f
@@ -81,6 +81,8 @@ static bool isHandleAtHead(struct SessionHandle *handle,
9d7d3f
 static CURLMcode add_next_timeout(struct timeval now,
9d7d3f
                                   struct Curl_multi *multi,
9d7d3f
                                   struct SessionHandle *d);
9d7d3f
+static CURLMcode multi_timeout(struct Curl_multi *multi,
9d7d3f
+                               long *timeout_ms);
9d7d3f
 
9d7d3f
 #ifdef DEBUGBUILD
9d7d3f
 static const char * const statename[]={
9d7d3f
@@ -804,10 +806,17 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
9d7d3f
   unsigned int i;
9d7d3f
   unsigned int nfds = extra_nfds;
9d7d3f
   struct pollfd *ufds = NULL;
9d7d3f
+  long timeout_internal;
9d7d3f
 
9d7d3f
   if(!GOOD_MULTI_HANDLE(multi))
9d7d3f
     return CURLM_BAD_HANDLE;
9d7d3f
 
9d7d3f
+  /* If the internally desired timeout is actually shorter than requested from
9d7d3f
+     the outside, then use the shorter time! */
9d7d3f
+  (void)multi_timeout(multi, &timeout_internal);
9d7d3f
+  if(timeout_internal < (long)timeout_ms)
9d7d3f
+    timeout_ms = (int)timeout_internal;
9d7d3f
+
9d7d3f
   /* Count up how many fds we have from the multi handle */
9d7d3f
   easy=multi->easy.next;
9d7d3f
   while(easy != &multi->easy) {
9d7d3f
-- 
9d7d3f
2.4.0
9d7d3f
9d7d3f
9d7d3f
From 3db7d3959815224b7a618860be783fed44fab72a Mon Sep 17 00:00:00 2001
9d7d3f
From: Daniel Stenberg <daniel@haxx.se>
9d7d3f
Date: Tue, 4 Jun 2013 13:22:40 +0200
9d7d3f
Subject: [PATCH 2/5] curl_multi_wait: only use internal timer if not -1
9d7d3f
9d7d3f
commit 29bf0598aad5 introduced a problem when the "internal" timeout is
9d7d3f
prefered to the given if shorter, as it didn't consider the case where
9d7d3f
-1 was returned. Now the internal timeout is only considered if not -1.
9d7d3f
9d7d3f
Reported-by: Tor Arntsen
9d7d3f
Bug: http://curl.haxx.se/mail/lib-2013-06/0015.html
9d7d3f
9d7d3f
Upstream-commit: 0bf5ce77aabe7307e41db13a0d03a63517fdc366
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 lib/multi.c | 5 +++--
9d7d3f
 1 file changed, 3 insertions(+), 2 deletions(-)
9d7d3f
9d7d3f
diff --git a/lib/multi.c b/lib/multi.c
9d7d3f
index c8dd97d..6dfce9b 100644
9d7d3f
--- a/lib/multi.c
9d7d3f
+++ b/lib/multi.c
9d7d3f
@@ -812,9 +812,10 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
9d7d3f
     return CURLM_BAD_HANDLE;
9d7d3f
 
9d7d3f
   /* If the internally desired timeout is actually shorter than requested from
9d7d3f
-     the outside, then use the shorter time! */
9d7d3f
+     the outside, then use the shorter time! But only if the internal timer
9d7d3f
+     is actually larger than 0! */
9d7d3f
   (void)multi_timeout(multi, &timeout_internal);
9d7d3f
-  if(timeout_internal < (long)timeout_ms)
9d7d3f
+  if((timeout_internal > 0) && (timeout_internal < (long)timeout_ms))
9d7d3f
     timeout_ms = (int)timeout_internal;
9d7d3f
 
9d7d3f
   /* Count up how many fds we have from the multi handle */
9d7d3f
-- 
9d7d3f
2.4.0
9d7d3f
9d7d3f
9d7d3f
From 761d88bb94e33a119f8e10083c33acf6fe216c79 Mon Sep 17 00:00:00 2001
9d7d3f
From: Daniel Stenberg <daniel@haxx.se>
9d7d3f
Date: Tue, 20 Aug 2013 22:45:47 +0200
9d7d3f
Subject: [PATCH 3/5] FTP: fix getsock during DO_MORE state
9d7d3f
9d7d3f
... when doing upload it would return the wrong values at times. This
9d7d3f
commit attempts to cleanup the mess.
9d7d3f
9d7d3f
Bug: http://curl.haxx.se/mail/lib-2013-08/0109.html
9d7d3f
Reported-by: Mike Mio
9d7d3f
9d7d3f
Upstream-commit: c4a7ca038e26a57df952b4ea560f9b718a5ebd1d
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 lib/ftp.c | 24 ++++++++++--------------
9d7d3f
 1 file changed, 10 insertions(+), 14 deletions(-)
9d7d3f
9d7d3f
diff --git a/lib/ftp.c b/lib/ftp.c
9d7d3f
index 4501116..63d1e64 100644
9d7d3f
--- a/lib/ftp.c
9d7d3f
+++ b/lib/ftp.c
9d7d3f
@@ -877,14 +877,9 @@ static int ftp_domore_getsock(struct connectdata *conn, curl_socket_t *socks,
9d7d3f
     return GETSOCK_BLANK;
9d7d3f
 
9d7d3f
   /* When in DO_MORE state, we could be either waiting for us to connect to a
9d7d3f
-     remote site, or we could wait for that site to connect to us. Or just
9d7d3f
-     handle ordinary commands.
9d7d3f
-
9d7d3f
-     When waiting for a connect, we will be in FTP_STOP state and then we wait
9d7d3f
-     for the secondary socket to become writeable. If we're in another state,
9d7d3f
-     we're still handling commands on the control (primary) connection.
9d7d3f
-
9d7d3f
-  */
9d7d3f
+   * remote site, or we could wait for that site to connect to us. Or just
9d7d3f
+   * handle ordinary commands.
9d7d3f
+   */
9d7d3f
 
9d7d3f
   switch(ftpc->state) {
9d7d3f
   case FTP_STOP:
9d7d3f
@@ -893,13 +888,12 @@ static int ftp_domore_getsock(struct connectdata *conn, curl_socket_t *socks,
9d7d3f
     return Curl_pp_getsock(&conn->proto.ftpc.pp, socks, numsocks);
9d7d3f
   }
9d7d3f
 
9d7d3f
-  socks[0] = conn->sock[SECONDARYSOCKET];
9d7d3f
-  if(ftpc->wait_data_conn) {
9d7d3f
-    socks[1] = conn->sock[FIRSTSOCKET];
9d7d3f
-    return GETSOCK_READSOCK(0) | GETSOCK_READSOCK(1);
9d7d3f
-  }
9d7d3f
+  /* if stopped and still in this state, then we're also waiting for a
9d7d3f
+     connect on the secondary connection */
9d7d3f
+  socks[0] = conn->sock[FIRSTSOCKET];
9d7d3f
+  socks[1] = conn->sock[SECONDARYSOCKET];
9d7d3f
 
9d7d3f
-  return GETSOCK_READSOCK(0);
9d7d3f
+  return GETSOCK_READSOCK(FIRSTSOCKET) | GETSOCK_WRITESOCK(SECONDARYSOCKET);
9d7d3f
 }
9d7d3f
 
9d7d3f
 /* This is called after the FTP_QUOTE state is passed.
9d7d3f
@@ -2421,6 +2415,8 @@ static CURLcode ftp_state_stor_resp(struct connectdata *conn,
9d7d3f
   if(data->set.ftp_use_port) {
9d7d3f
     bool connected;
9d7d3f
 
9d7d3f
+    state(conn, FTP_STOP); /* no longer in STOR state */
9d7d3f
+
9d7d3f
     result = AllowServerConnect(conn, &connected);
9d7d3f
     if(result)
9d7d3f
       return result;
9d7d3f
-- 
9d7d3f
2.4.0
9d7d3f
9d7d3f
9d7d3f
From 5b18b86746cf09208e57adb69edcf411b10f5e30 Mon Sep 17 00:00:00 2001
9d7d3f
From: Daniel Stenberg <daniel@haxx.se>
9d7d3f
Date: Sat, 6 Apr 2013 17:49:58 +0200
9d7d3f
Subject: [PATCH 4/5] ftp tests: libcurl returns CURLE_FTP_ACCEPT_FAILED better
9d7d3f
 now
9d7d3f
9d7d3f
Since commit 57aeabcc1a20f, it handles errors on the control connection
9d7d3f
while waiting for the data connection better.
9d7d3f
9d7d3f
Test 591 and 592 are updated accordingly.
9d7d3f
9d7d3f
Upstream-commit: 18f0ab7bd353289049ca06c4a7105473e37a8f20
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 tests/data/test591 | 4 ++--
9d7d3f
 tests/data/test592 | 5 +++--
9d7d3f
 2 files changed, 5 insertions(+), 4 deletions(-)
9d7d3f
9d7d3f
diff --git a/tests/data/test591 b/tests/data/test591
9d7d3f
index 42a2271..1455a38 100644
9d7d3f
--- a/tests/data/test591
9d7d3f
+++ b/tests/data/test591
9d7d3f
@@ -63,9 +63,9 @@ TYPE I
9d7d3f
 STOR 591
9d7d3f
 QUIT
9d7d3f
 </protocol>
9d7d3f
-# CURLE_UPLOAD_FAILED = 25
9d7d3f
+# CURLE_FTP_ACCEPT_FAILED = 10
9d7d3f
 <errorcode>
9d7d3f
-25
9d7d3f
+10
9d7d3f
 </errorcode>
9d7d3f
 <upload>
9d7d3f
 </upload>
9d7d3f
diff --git a/tests/data/test592 b/tests/data/test592
9d7d3f
index 23aa6c4..f443205 100644
9d7d3f
--- a/tests/data/test592
9d7d3f
+++ b/tests/data/test592
9d7d3f
@@ -62,10 +62,11 @@ EPRT |1|
9d7d3f
 PORT
9d7d3f
 TYPE I
9d7d3f
 STOR 592
9d7d3f
+QUIT
9d7d3f
 </protocol>
9d7d3f
-# 28 == CURLE_OPERATION_TIMEDOUT
9d7d3f
+# CURLE_FTP_ACCEPT_FAILED = 10
9d7d3f
 <errorcode>
9d7d3f
-28
9d7d3f
+10
9d7d3f
 </errorcode>
9d7d3f
 <upload>
9d7d3f
 </upload>
9d7d3f
-- 
9d7d3f
2.4.0
9d7d3f
9d7d3f
9d7d3f
From 599ef7d7ec8ed7a979df1cd3180819359e6af97f Mon Sep 17 00:00:00 2001
9d7d3f
From: Daniel Stenberg <daniel@haxx.se>
9d7d3f
Date: Thu, 6 Jun 2013 22:20:39 +0200
9d7d3f
Subject: [PATCH 5/5] lib1500: remove bad check
9d7d3f
9d7d3f
After curl_multi_wait() returns, this test checked that we got exactly
9d7d3f
one file descriptor told to read from, but we cannot be sure that is
9d7d3f
true. curl_multi_wait() will sometimes return earlier without any file
9d7d3f
descriptor to handle, just just because it is a suitable time to call
9d7d3f
*perform().
9d7d3f
9d7d3f
This problem showed up with commit 29bf0598.
9d7d3f
9d7d3f
Bug: http://curl.haxx.se/mail/lib-2013-06/0029.html
9d7d3f
Reported-by: Fabian Keil
9d7d3f
9d7d3f
Upstream-commit: 87cf677eca55abee88f0a9dced9e6fa570143873
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 tests/libtest/lib1500.c | 5 -----
9d7d3f
 1 file changed, 5 deletions(-)
9d7d3f
9d7d3f
diff --git a/tests/libtest/lib1500.c b/tests/libtest/lib1500.c
9d7d3f
index 784bdb2..736a817 100644
9d7d3f
--- a/tests/libtest/lib1500.c
9d7d3f
+++ b/tests/libtest/lib1500.c
9d7d3f
@@ -61,11 +61,6 @@ int test(char *URL)
9d7d3f
       res = -1;
9d7d3f
       goto test_cleanup;
9d7d3f
     }
9d7d3f
-    if (num != 1) {
9d7d3f
-      printf("curl_multi_wait() returned on %d handle(s), expected 1\n", num);
9d7d3f
-      res = -1;
9d7d3f
-      goto test_cleanup;
9d7d3f
-    }
9d7d3f
 
9d7d3f
     abort_on_test_timeout();
9d7d3f
 
9d7d3f
-- 
9d7d3f
2.4.0
9d7d3f