From fd884a3cd21c873f6fe953d37b0c6e3fef58fad6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 4 Nov 2004 16:17:23 +0000 Subject: more retry stuff --- src/main.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index d0c762081..e670f194d 100644 --- a/src/main.c +++ b/src/main.c @@ -386,6 +386,7 @@ static void help(void) " -R/--remote-time Set the remote file's time on the local output", " --retry Retry request times if transient problems occur", " --retry-delay When retrying, wait this many seconds between each", + " --retry-max-time Retry only within this period", " -s/--silent Silent mode. Don't output anything", " -S/--show-error Show error. With -s, make curl show errors when they occur", " --socks Use SOCKS5 proxy on given host + port", @@ -529,6 +530,7 @@ struct Configurable { bool tcp_nodelay; long req_retry; /* number of retries */ long retry_delay; /* delay between retries (in seconds) */ + long retry_maxtime; /* maximum time to keep retrying */ }; /* global variable to hold info about libcurl */ @@ -1212,6 +1214,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */ {"$f", "proxy-basic", FALSE}, {"$g", "retry", TRUE}, {"$h", "retry-delay", TRUE}, + {"$i", "retry-max-time", TRUE}, {"0", "http1.0", FALSE}, {"1", "tlsv1", FALSE}, {"2", "sslv2", FALSE}, @@ -1555,6 +1558,10 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */ if(str2num(&config->retry_delay, nextarg)) return PARAM_BAD_NUMERIC; break; + case 'i': /* --retry-max-time */ + if(str2num(&config->retry_maxtime, nextarg)) + return PARAM_BAD_NUMERIC; + break; } break; case '#': /* added 19990617 larsa */ @@ -2809,6 +2816,7 @@ operate(struct Configurable *config, int argc, char *argv[]) long retry_numretries; long retry_sleep = retry_sleep_default; long response; + struct timeval retrystart; char *env; #ifdef CURLDEBUG @@ -3513,10 +3521,17 @@ operate(struct Configurable *config, int argc, char *argv[]) retry_numretries = config->req_retry; + retrystart = curlx_tvnow(); + do { res = curl_easy_perform(curl); - if(retry_numretries) { + /* if retry-max-time is non-zero, make sure we haven't exceeded the + time */ + if(retry_numretries && + (!config->retry_maxtime || + (curlx_tvdiff(curlx_tvnow(), retrystart)< + config->retry_maxtime*1000)) ) { enum { RETRY_NO, RETRY_TIMEOUT, -- cgit v1.2.3