summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2023-09-13 14:35:44 +0900
committerRyo Nakamura <upa@haeena.net>2023-11-01 19:54:18 +0900
commit139ba12f1a7c35a572d33991f4c3960f61490dfe (patch)
tree67b1b88c5bb1119e7d8d1f54b36f1ef8cf29ff0a /src/main.c
parentcfbadebe6dfeb148d687df3bc91448674054cb82 (diff)
write total transferred bytes and number of files
at the end of output when serverity is notice.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c63
1 files changed, 32 insertions, 31 deletions
diff --git a/src/main.c b/src/main.c
index f57ca97..f7e627a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -536,17 +536,42 @@ struct xfer_stat {
};
struct xfer_stat x;
-void print_stat_thread_cleanup(void *arg)
+void print_stat(bool final)
{
+ struct pollfd pfd = { .fd = msg_fd, .events = POLLIN };
struct mscp_stats s;
+ char buf[8192];
+ int timeout;
+
+ if (poll(&pfd, 1, !final ? 100 : 0) < 0) {
+ fprintf(stderr, "poll: %s\n", strerror(errno));
+ return;
+ }
+
+ if (pfd.revents & POLLIN) {
+ memset(buf, 0, sizeof(buf));
+ if (read(msg_fd, buf, sizeof(buf)) < 0) {
+ fprintf(stderr, "read: %s\n", strerror(errno));
+ return;
+ }
+ print_cli("\r\033[K" "%s", buf);
+ }
gettimeofday(&x.after, NULL);
- mscp_get_stats(m, &s);
- x.total = s.total;
- x.done = s.done;
+ if (calculate_timedelta(&x.before, &x.after) > 1 || final) {
+ mscp_get_stats(m, &s);
+ x.total = s.total;
+ x.done = s.done;
+ print_progress(!final ? &x.before : &x.start, &x.after,
+ x.total, !final ? x.last : 0, x.done, final);
+ x.before = x.after;
+ x.last = x.done;
+ }
+}
- /* print progress from the beginning */
- print_progress(&x.start, &x.after, x.total, 0, x.done, true);
+void print_stat_thread_cleanup(void *arg)
+{
+ print_stat(true);
print_cli("\n"); /* final output */
}
@@ -565,31 +590,7 @@ void *print_stat_thread(void *arg)
pthread_cleanup_push(print_stat_thread_cleanup, NULL);
while (true) {
- if (poll(&pfd, 1, 100) < 0) {
- fprintf(stderr, "poll: %s\n", strerror(errno));
- return NULL;
- }
-
- if (pfd.revents & POLLIN) {
- memset(buf, 0, sizeof(buf));
- if (read(msg_fd, buf, sizeof(buf)) < 0) {
- fprintf(stderr, "read: %s\n", strerror(errno));
- return NULL;
- }
- print_cli("\r\033[K" "%s", buf);
- }
-
- gettimeofday(&x.after, NULL);
- if (calculate_timedelta(&x.before, &x.after) > 1) {
- mscp_get_stats(m, &s);
- x.total = s.total;
- x.done = s.done;
-
- print_progress(&x.before, &x.after, x.total, x.last, x.done,
- false);
- x.before = x.after;
- x.last = x.done;
- }
+ print_stat(false);
}
pthread_cleanup_pop(1);