From e01a38e4a7dcc9a98b84c8dddce83a062b597db7 Mon Sep 17 00:00:00 2001 From: tiptorrent development team Date: Wed, 30 Nov 2022 11:57:42 +0100 Subject: add tip_client_report() --- src/main.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 969e62d..6033e8a 100644 --- a/src/main.c +++ b/src/main.c @@ -592,6 +592,31 @@ static int tip_client_run(struct tip_client *cli, int fd, const char *addr, return 0; } +static int tip_client_report(struct tip_client *cli, const struct timeval *tv, + uint64_t data_len) +{ + if (cli->state == TIP_CLIENT_DONE) { + printf("OK.\n"); + syslog(LOG_INFO, "Done in %lu.%06lu seconds (%lu Mbytes/second). " + "Direct from server: %u Redirected: %u\n", + tv->tv_sec, tv->tv_usec, + tv->tv_sec > 0 ? data_len / 1024000 / tv->tv_sec : data_len / 1024000, + tip_client_stats.direct_from_server, + tip_client_stats.redirects); + return EXIT_SUCCESS; + } + + printf("Failure, see syslog for details.\n"); + syslog(LOG_INFO, "Failure after %lu.%06lu seconds (%lu Mbytes/second). " + "Direct from server: %u Redirected: %u\n", + tv->tv_sec, tv->tv_usec, + tv->tv_sec > 0 ? data_len / 1024000 / tv->tv_sec : data_len / 1024000, + tip_client_stats.direct_from_server, + tip_client_stats.redirects); + + return EXIT_FAILURE; +} + int main(int argc, char *argv[]) { struct timeval tv_start, tv_stop, tv; @@ -648,25 +673,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - if (_cli.state == TIP_CLIENT_DONE) { - printf("OK.\n"); - syslog(LOG_INFO, "Done in %lu.%06lu seconds (%lu Mbytes/second). " - "Direct from server: %u Redirected: %u\n", - tv.tv_sec, tv.tv_usec, - tv.tv_sec > 0 ? data_len / 1024000 / tv.tv_sec : data_len / 1024000, - tip_client_stats.direct_from_server, - tip_client_stats.redirects); - return EXIT_SUCCESS; - } - - printf("Failure, see syslog for details.\n"); - syslog(LOG_INFO, "Failure after %lu.%06lu seconds (%lu Mbytes/second). " - "Direct from server: %u Redirected: %u\n", - tv.tv_sec, tv.tv_usec, - tv.tv_sec > 0 ? data_len / 1024000 / tv.tv_sec : data_len / 1024000, - tip_client_stats.direct_from_server, - tip_client_stats.redirects); - return EXIT_FAILURE; + return tip_client_report(&_cli, &tv, data_len); err_bailout: if (_cli.fatal) -- cgit v1.2.3-18-g5258