All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 4/5] client/player: Print transport progress
Date: Thu, 15 Dec 2022 13:10:36 -0800	[thread overview]
Message-ID: <20221215211037.2686489-4-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20221215211037.2686489-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This uses bt_shell_echo to print out the transfer progress on the echo
area.
---
 client/player.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/client/player.c b/client/player.c
index e73ed6ac925a..6e33274d320d 100644
--- a/client/player.c
+++ b/client/player.c
@@ -25,6 +25,7 @@
 #include <sys/uio.h>
 #include <wordexp.h>
 #include <sys/timerfd.h>
+#include <sys/stat.h>
 
 #include <glib.h>
 
@@ -91,6 +92,7 @@ struct transport {
 	uint16_t mtu[2];
 	char *filename;
 	int fd;
+	struct stat stat;
 	struct io *io;
 	uint32_t seq;
 	struct io *timer_io;
@@ -3379,6 +3381,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) {
@@ -3399,10 +3402,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: %zd/%zd bytes",
 				transport->seq, secs,
 				(nsecs + 500000) / 1000000,
-				ret);
+				offset, transport->stat.st_size);
 	}
 
 	free(buf);
-- 
2.37.3


  parent reply	other threads:[~2022-12-15 21:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15 21:10 [PATCH BlueZ v2 1/5] client/player: Make transport.send non-blocking Luiz Augusto von Dentz
2022-12-15 21:10 ` [PATCH BlueZ v2 2/5] shared/shell: Add bt_shell_echo Luiz Augusto von Dentz
2022-12-15 21:10 ` [PATCH BlueZ v2 3/5] client/player: Use bt_shell_echo to print transfer progress Luiz Augusto von Dentz
2022-12-15 21:10 ` Luiz Augusto von Dentz [this message]
2022-12-15 21:10 ` [PATCH BlueZ v2 5/5] client/player: Fix transport.send/receice tab completion Luiz Augusto von Dentz
2022-12-15 23:08 ` [BlueZ,v2,1/5] client/player: Make transport.send non-blocking bluez.test.bot
2022-12-16  0:30 ` [PATCH BlueZ v2 1/5] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221215211037.2686489-4-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.