Patchwork [U-Boot,4/8] tftpput: move common code into separate functions

login
register
mail settings
Submitter Simon Glass
Date Oct. 22, 2011, 4:51 a.m.
Message ID <1319259100-11376-5-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/121142/
State New, archived
Headers show

Comments

Simon Glass - Oct. 22, 2011, 4:51 a.m.
We want to show block markers on completion of get and put, so
move this common code into separate functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 net/tftp.c |   70 ++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 40 insertions(+), 30 deletions(-)

Patch

diff --git a/net/tftp.c b/net/tftp.c
index da8eeaa..4ad85a5 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -195,6 +195,42 @@  static void TftpTimeout(void);
 
 /**********************************************************************/
 
+static void show_block_marker(void)
+{
+	ulong pos = TftpBlock * TftpBlkSize + TftpBlockWrapOffset;
+
+#ifdef CONFIG_TFTP_TSIZE
+	if (TftpTsize) {
+		while (TftpNumchars <
+			/* TODO: needs to be different for put */
+			pos * 50 / TftpTsize) {
+			putc('#');
+			TftpNumchars++;
+		}
+	}
+#endif
+	else {
+		if (((TftpBlock - 1) % 10) == 0)
+			putc('#');
+		else if ((TftpBlock % (10 * HASHES_PER_LINE)) == 0)
+			puts("\n\t ");
+	}
+}
+
+/* The TFTP get or put is complete */
+static void tftp_complete(void)
+{
+#ifdef CONFIG_TFTP_TSIZE
+	/* Print hash marks for the last packet received */
+	while (TftpTsize && TftpNumchars < 49) {
+		putc('#');
+		TftpNumchars++;
+	}
+#endif
+	puts("\ndone\n");
+	NetState = NETLOOP_SUCCESS;
+}
+
 static void
 TftpSend(void)
 {
@@ -400,21 +436,8 @@  TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 				TftpBlkSize * TFTP_SEQUENCE_SIZE;
 			printf("\n\t %lu MB received\n\t ",
 				TftpBlockWrapOffset>>20);
-		}
-#ifdef CONFIG_TFTP_TSIZE
-		else if (TftpTsize) {
-			while (TftpNumchars <
-			       NetBootFileXferSize * 50 / TftpTsize) {
-				putc('#');
-				TftpNumchars++;
-			}
-		}
-#endif
-		else {
-			if (((TftpBlock - 1) % 10) == 0)
-				putc('#');
-			else if ((TftpBlock % (10 * HASHES_PER_LINE)) == 0)
-				puts("\n\t ");
+		} else {
+			show_block_marker();
 		}
 
 		if (TftpState == STATE_SEND_RRQ)
@@ -498,21 +521,8 @@  TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 		}
 		else
 #endif
-		if (len < TftpBlkSize) {
-			/*
-			 *	We received the whole thing.  Try to
-			 *	run it.
-			 */
-#ifdef CONFIG_TFTP_TSIZE
-			/* Print hash marks for the last packet received */
-			while (TftpTsize && TftpNumchars < 49) {
-				putc('#');
-				TftpNumchars++;
-			}
-#endif
-			puts("\ndone\n");
-			NetState = NETLOOP_SUCCESS;
-		}
+		if (len < TftpBlkSize)
+			tftp_complete();
 		break;
 
 	case TFTP_ERROR: