mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/8] tftp: use generic progression bar
Date: Thu, 24 Jun 2010 11:35:04 +0200	[thread overview]
Message-ID: <1277372108-30332-5-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1277372108-30332-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/tftp.c |   34 +++++++++++++---------------------
 1 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 338359b..4b60cc8 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -13,13 +13,11 @@
 #include <errno.h>
 #include <libgen.h>
 #include <fcntl.h>
+#include <progress.h>
 #include <linux/err.h>
 
 #define TFTP_PORT	69		/* Well known TFTP port #		*/
 #define TIMEOUT		5		/* Seconds to timeout for a lost pkt	*/
-# define TIMEOUT_COUNT	10		/* # of timeouts before giving up  */
-					/* (for checking the image size)	*/
-#define HASHES_PER_LINE	65		/* Number of "loading" hashes per line	*/
 
 /*
  *	TFTP operations.
@@ -50,6 +48,7 @@ static int		tftp_err;
 static char *tftp_filename;
 static struct net_connection *tftp_con;
 static int net_store_fd;
+static int tftp_size;
 
 static int tftp_send(void)
 {
@@ -84,6 +83,8 @@ static int tftp_send(void)
 		break;
 	}
 
+	tftp_timer_start = get_time_ns();
+	show_progress(tftp_size);
 	ret = net_udp_send(tftp_con, len);
 
 	return ret;
@@ -127,20 +128,6 @@ static void tftp_handler(char *packet, unsigned len)
 		len -= 2;
 		tftp_block = ntohs(*(uint16_t *)pkt);
 
-		/*
-		 * RFC1350 specifies that the first data packet will
-		 * have sequence number 1. If we receive a sequence
-		 * number of 0 this means that there was a wrap
-		 * around of the (16 bit) counter.
-		 */
-		if (tftp_block) {
-			if (((tftp_block - 1) % 10) == 0) {
-				putchar('#');
-			} else if ((tftp_block % (10 * HASHES_PER_LINE)) == 0) {
-				puts("\n\t ");
-			}
-		}
-
 		if (tftp_state == STATE_RRQ)
 			debug("Server did not acknowledge timeout option!\n");
 
@@ -165,7 +152,9 @@ static void tftp_handler(char *packet, unsigned len)
 			break;
 
 		tftp_last_block = tftp_block;
-		tftp_timer_start = get_time_ns();
+
+		if (!(tftp_block % 10))
+			tftp_size++;
 
 		ret = write(net_store_fd, pkt + 2, len);
 		if (ret < 0) {
@@ -205,6 +194,8 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 	char *remotefile;
 	char ip1[16];
 
+	tftp_size = 0;
+
 	if (argc < 2)
 		return COMMAND_ERROR_USAGE;
 
@@ -229,10 +220,12 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 
 	tftp_filename = remotefile;
 
-	printf("TFTP from server %s; Filename: '%s'\nLoading: ",
+	printf("TFTP from server %s; Filename: '%s'\n",
 			ip_to_string(net_get_serverip(), ip1),
 			tftp_filename);
 
+	init_progression_bar(0);
+
 	tftp_timer_start = get_time_ns();
 	tftp_state = STATE_RRQ;
 	tftp_block = 0;
@@ -248,8 +241,7 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 		}
 		net_poll();
 		if (is_timeout(tftp_timer_start, SECOND)) {
-			tftp_timer_start = get_time_ns();
-			printf("T ");
+			show_progress(-1);
 			tftp_send();
 		}
 	}
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2010-06-24  9:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-24  9:35 more network patches Sascha Hauer
2010-06-24  9:35 ` [PATCH 1/8] tftp: remove unused variables Sascha Hauer
2010-06-24  9:35 ` [PATCH 2/8] add progression bar function Sascha Hauer
2010-06-24  9:35 ` [PATCH 3/8] cfi flash driver: Use generic " Sascha Hauer
2010-06-24  9:35 ` Sascha Hauer [this message]
2010-06-24  9:35 ` [PATCH 5/8] tftp: Add push support Sascha Hauer
2010-06-24  9:35 ` [PATCH 6/8] nfs: Use generic progression bar Sascha Hauer
2010-06-24  9:35 ` [PATCH 7/8] nfs: resend requests after timeout Sascha Hauer
2010-06-24  9:35 ` [PATCH 8/8] tftp: update doxygen information Sascha Hauer

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=1277372108-30332-5-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox