summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index fef2447..ed3b032 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,6 +54,7 @@ struct tip_client {
uint64_t data_len;
uint64_t content_len;
int state;
+ int num_retries;
int fd;
bool error;
bool redirected;
@@ -444,6 +445,9 @@ static uint32_t select_file_chunk(bool *file_chunk)
static char _filename[PATH_MAX + 1];
+#define MAX_RETRIES 5
+#define WAIT_RETRY 5 /* wait 5 seconds before retrying. */
+
int main(int argc, char *argv[])
{
struct timeval tv_start, tv_stop, tv;
@@ -471,7 +475,7 @@ int main(int argc, char *argv[])
k = select_file_chunk(file_chunk);
snprintf(_filename, sizeof(_filename), "%s.%u", argv[2], k);
filename = _filename;
-
+retry:
syslog(LOG_INFO, "Requesting file %s to server\n", filename);
tip_client_connect(argv[1]);
@@ -482,7 +486,14 @@ int main(int argc, char *argv[])
if (_cli.error) {
syslog(LOG_ERR, "Failed to fetch file %s\n", filename);
- break;
+ sleep(WAIT_RETRY);
+ if (_cli.num_retries++ >= MAX_RETRIES) {
+ syslog(LOG_ERR, "Maximum number of retries (%d), bailing out!\n",
+ MAX_RETRIES);
+ break;
+ }
+ _cli.error = false;
+ goto retry;
}
tip_client_progress(&_cli, true);