From b3dfd736d4ed65e86a805e9a2fbecab4d392bc1d Mon Sep 17 00:00:00 2001
From: gnawhleinad <danielleehwang@gmail.com>
Date: Sun, 17 Aug 2014 17:35:37 -0700
Subject: [PATCH 2/2] tool: limit --retry-connrefused to only connection refused

---
 src/tool_operate.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/tool_operate.c b/src/tool_operate.c
index e9c85c1..28d4c07 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -1383,6 +1383,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
             enum {
               RETRY_NO,
               RETRY_TIMEOUT,
+              RETRY_CONNREFUSED,
               RETRY_HTTP,
               RETRY_FTP,
               RETRY_LAST /* not used */
@@ -1391,10 +1392,16 @@ static CURLcode operate_do(struct GlobalConfig *global,
             if((CURLE_OPERATION_TIMEDOUT == res) ||
                (CURLE_COULDNT_RESOLVE_HOST == res) ||
                (CURLE_COULDNT_RESOLVE_PROXY == res) ||
-               (CURLE_FTP_ACCEPT_TIMEOUT == res) ||
-               (config->retry_connrefused && (CURLE_COULDNT_CONNECT == res)))
+               (CURLE_FTP_ACCEPT_TIMEOUT == res))
               /* retry timeout always */
               retry = RETRY_TIMEOUT;
+            else if (config->retry_connrefused && 
+                     (CURLE_COULDNT_CONNECT == res)) {
+              long oserrno;
+              curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &oserrno);
+              if (ECONNREFUSED == oserrno)
+                retry = RETRY_CONNREFUSED;
+            }
             else if((CURLE_OK == res) ||
                     (config->failonerror &&
                      (CURLE_HTTP_RETURNED_ERROR == res))) {
@@ -1442,7 +1449,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
             if(retry) {
               static const char * const m[]={
-                NULL, "timeout", "HTTP error", "FTP error"
+                NULL, "timeout", "connection refused", "HTTP error", "FTP error"
               };
               warnf(config, "Transient problem: %s "
                     "Will retry in %ld seconds. "
-- 
1.7.2.3
