summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortiptorrent development team <tiptorrent@soleta.eu>2022-02-08 12:19:07 +0100
committertiptorrent development team <tiptorrent@soleta.eu>2022-02-08 12:21:05 +0100
commit39e60a019a2bfbc88bc26a3577eeb7f259159a0e (patch)
tree3f6bf6ecce8f1982558ac574a6c2f8a48523716f
parente9de4e482f225b2987ab0368cea2fae835b4967e (diff)
bail out after maximum number of retries
stop downloading remaining chunks if one is missing after the maximum number of retries.
-rw-r--r--src/main.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 88e5bd8..3e88308 100644
--- a/src/main.c
+++ b/src/main.c
@@ -534,7 +534,7 @@ int main(int argc, char *argv[])
uint64_t data_len = 0, file_size = 0;
bool file_chunk[MAX_CHUNKS] = {};
uint64_t chunk_size;
- int i, k, fd;
+ int i, k, fd, ret;
if (argc != 3) {
printf("%s [ip] [file]\n", argv[0]);
@@ -553,7 +553,11 @@ int main(int argc, char *argv[])
do {
filename = argv[2];
_cli.state = TIP_CLIENT_HEAD_HEADER;
- } while (tip_client_request_file(&_cli, addr, filename) > 0);
+ ret = tip_client_request_file(&_cli, addr, filename);
+ } while (ret > 0);
+
+ if (ret < 0)
+ goto err_max_retries;
if (_cli.state != TIP_CLIENT_DONE)
goto err;
@@ -574,8 +578,11 @@ int main(int argc, char *argv[])
do {
syslog(LOG_INFO, "Requesting file %s to server\n", filename);
_cli.state = TIP_CLIENT_GET_HEADER;
+ ret = tip_client_request_file(&_cli, addr, filename);
+ } while (ret > 0);
- } while (tip_client_request_file(&_cli, addr, filename) > 0);
+ if (ret < 0)
+ goto err_max_retries;
tip_client_progress(&_cli, true);
file_chunk[k] = true;
@@ -605,4 +612,11 @@ err:
tip_client_stats.direct_from_server,
tip_client_stats.redirects);
return EXIT_FAILURE;
+
+err_max_retries:
+ syslog(LOG_INFO, "Failure after maximum number of retries. "
+ "Direct from server: %u Redirected: %u\n",
+ tip_client_stats.direct_from_server,
+ tip_client_stats.redirects);
+ return EXIT_FAILURE;
}