diff options
author | tiptorrent development team <tiptorrent@soleta.eu> | 2022-11-30 11:57:42 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2022-11-30 12:27:46 +0100 |
commit | e01a38e4a7dcc9a98b84c8dddce83a062b597db7 (patch) | |
tree | 3a217cbf5a5ba9b2b60d7bde7b7c82960df4c699 | |
parent | 7d70e7abec6eb62edfb11363d871c65a12323617 (diff) |
add tip_client_report()
-rw-r--r-- | src/main.c | 45 |
1 files changed, 26 insertions, 19 deletions
@@ -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) |