diff options
-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; } |