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