diff options
author | tiptorrent development team <tiptorrent@soleta.eu> | 2022-02-08 12:19:07 +0100 |
---|---|---|
committer | tiptorrent development team <tiptorrent@soleta.eu> | 2022-02-08 12:21:05 +0100 |
commit | 39e60a019a2bfbc88bc26a3577eeb7f259159a0e (patch) | |
tree | 3f6bf6ecce8f1982558ac574a6c2f8a48523716f /src/main.c | |
parent | e9de4e482f225b2987ab0368cea2fae835b4967e (diff) |
bail out after maximum number of retries
stop downloading remaining chunks if one is missing after the maximum number of
retries.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -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; } |