summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authortiptorrent development team <tiptorrent@soleta.eu>2022-11-30 11:57:42 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2022-11-30 12:27:46 +0100
commite01a38e4a7dcc9a98b84c8dddce83a062b597db7 (patch)
tree3a217cbf5a5ba9b2b60d7bde7b7c82960df4c699 /src/main.c
parent7d70e7abec6eb62edfb11363d871c65a12323617 (diff)
add tip_client_report()
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c45
1 files changed, 26 insertions, 19 deletions
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)