summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortiptorrent development team <tiptorrent@soleta.eu>2021-10-02 11:46:22 +0200
committertiptorrent development team <tiptorrent@soleta.eu>2021-10-02 11:46:22 +0200
commit486e1b8351429e5e4af67dfa2a95a8bc8e5cdc91 (patch)
tree36be17927b560706ee51dd45f0efff9bdb0c1fa6
parent48da60d88330e806469010423b6aab038e56b52b (diff)
add retry logic
- if the connection to server fails, retry 5 times, sleeping 5 seconds before each retry. - if the redirection fails, go back and request the chunk from the server again.
-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);