Hello,

I have executed http://curl.haxx.se/mail/archive-2010-05/0066.html. The
objective was to add an option to consider "connection refused" errors as
transient in a retry.

I have tested my changes using the following approach:
https://gist.github.com/gnawhleinad/6860bedb4de5a3776ecd#file-readme-md

The diff is attached in the e-mail. It is also available on
https://gist.github.com/gnawhleinad/6860bedb4de5a3776ecd#file-diff

Thanks,

Daniel Hwang
From fb523a4812557b32db97bcf9c744f2a1f14796d1 Mon Sep 17 00:00:00 2001
From: gnawhleinad <[email protected]>
Date: Thu, 14 Aug 2014 01:54:03 -0700
Subject: [PATCH] tool: add --retry-connrefused

To consider "connection refused" errors as transient errors during
retry.

Bug: http://curl.haxx.se/mail/archive-2010-05/0066.html
---
 src/tool_cfgable.h  |    1 +
 src/tool_getparam.c |    4 ++++
 src/tool_help.c     |    1 +
 src/tool_operate.c  |    3 ++-
 4 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h
index 4ef2690..72b8ed6 100644
--- a/src/tool_cfgable.h
+++ b/src/tool_cfgable.h
@@ -169,6 +169,7 @@ struct OperationConfig {
 
   bool tcp_nodelay;
   long req_retry;           /* number of retries */
+  bool retry_connrefused;   /* consider connection refused as a transient error */
   long retry_delay;         /* delay between retries (in seconds) */
   long retry_maxtime;       /* maximum time to keep retrying */
 
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index 180878b..508df5c 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -127,6 +127,7 @@ static const struct LongShort aliases[]= {
   {"$e", "proxy-digest",             FALSE},
   {"$f", "proxy-basic",              FALSE},
   {"$g", "retry",                    TRUE},
+  {"$M", "retry-connrefused",        FALSE},
   {"$h", "retry-delay",              TRUE},
   {"$i", "retry-max-time",           TRUE},
   {"$k", "proxy-negotiate",          FALSE},
@@ -785,6 +786,9 @@ ParameterError getparameter(char *flag,    /* f or -long-flag */
         if(err)
           return err;
         break;
+      case 'M': /* --retry-connrefused */
+        config->retry_connrefused = toggle;
+        break;
       case 'h': /* --retry-delay */
         err = str2unum(&config->retry_delay, nextarg);
         if(err)
diff --git a/src/tool_help.c b/src/tool_help.c
index 43ab1a9..327f3b0 100644
--- a/src/tool_help.c
+++ b/src/tool_help.c
@@ -185,6 +185,7 @@ static const char *const helptext[] = {
   "     --resolve HOST:PORT:ADDRESS  Force resolve of HOST:PORT to ADDRESS",
   "     --retry NUM   "
   "Retry request NUM times if transient problems occur",
+  "     --retry-connrefused  Consider \"connection refused\" a transient error",
   "     --retry-delay SECONDS "
   "When retrying, wait this many seconds between each",
   "     --retry-max-time SECONDS  Retry only within this period",
diff --git a/src/tool_operate.c b/src/tool_operate.c
index fd2fd6d..e9c85c1 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -1391,7 +1391,8 @@ 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))
+               (CURLE_FTP_ACCEPT_TIMEOUT == res) ||
+               (config->retry_connrefused && (CURLE_COULDNT_CONNECT == res)))
               /* retry timeout always */
               retry = RETRY_TIMEOUT;
             else if((CURLE_OK == res) ||
-- 
1.7.2.3

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

Reply via email to