client/player: Print transport progress
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 14 Dec 2022 21:01:07 +0000 (13:01 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 5 Jan 2024 10:11:34 +0000 (15:41 +0530)
This uses bt_shell_echo to print out the transfer progress on the echo
area.

client/player.c

index 4820702..a9fdf29 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/uio.h>
 #include <wordexp.h>
 #include <sys/timerfd.h>
+#include <sys/stat.h>
 
 #include <glib.h>
 
@@ -90,6 +91,7 @@ struct transport {
        uint16_t mtu[2];
        char *filename;
        int fd;
+       struct stat stat;
        struct io *io;
        uint32_t seq;
        struct io *timer_io;
@@ -3378,6 +3380,7 @@ static int transport_send_seq(struct transport *transport, int fd, uint32_t num)
        for (i = 0; i < num; i++, transport->seq++) {
                ssize_t ret;
                int secs = 0, nsecs = 0;
+               off_t offset;
 
                ret = read(fd, buf, transport->mtu[1]);
                if (ret <= 0) {
@@ -3398,10 +3401,19 @@ static int transport_send_seq(struct transport *transport, int fd, uint32_t num)
 
                elapsed_time(!transport->seq, &secs, &nsecs);
 
-               bt_shell_echo("[seq %d %d.%03ds] send: %zd bytes ",
+               if (!transport->seq && fstat(fd, &transport->stat) < 0) {
+                       bt_shell_printf("fstat failed: %s (%d)",
+                                                       strerror(errno), errno);
+                       free(buf);
+                       return -errno;
+               }
+
+               offset = lseek(fd, 0, SEEK_CUR);
+
+               bt_shell_echo("[seq %d %d.%03ds] send: %lld/%lld bytes",
                                transport->seq, secs,
                                (nsecs + 500000) / 1000000,
-                               ret);
+                               offset, transport->stat.st_size);
        }
 
        free(buf);