From 68a8f0f1f34dde836609bf34506d32bfdb2b1f6e Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Thu, 29 Jan 2026 01:23:29 +0100 Subject: [PATCH] net: lwip: wget: rework the '#' printing Currently, the LWIP wget command prints excessive amount of progress indicator '#' for very long file downloads, limit this to one line that scales according to transfer size. The HTTP server does report the size of the entire file in protocol headers, which are received before the actual data transfer. Cache this information and use it to adaptively print progress indicator '#' until it fills one entire line worth of '#', which indicates the transfer has completed. This way, long transfers don't print pages of '#', but every transfer will print exactly one line worth of '#'. The algorithm for '#' printing is the same as TFTP tsize one. Signed-off-by: Marek Vasut Acked-by: Jerome Forissier --- net/lwip/wget.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/net/lwip/wget.c b/net/lwip/wget.c index 55bd2b72e26..008f3b395e7 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -37,6 +37,8 @@ struct wget_ctx { ulong size; ulong prevsize; ulong start_time; + ulong content_len; + ulong hash_count; enum done_state done; }; @@ -152,6 +154,7 @@ static int store_block(struct wget_ctx *ctx, void *src, u16_t len) { ulong store_addr = ctx->daddr; uchar *ptr; + ulong pos; /* Avoid overflow */ if (wget_info->buffer_size && wget_info->buffer_size < ctx->size + len) @@ -174,10 +177,12 @@ static int store_block(struct wget_ctx *ctx, void *src, u16_t len) ctx->daddr += len; ctx->size += len; - if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { - if (!wget_info->silent) - printf("#"); - ctx->prevsize = ctx->size; + + pos = clamp(ctx->size, 0UL, ctx->content_len); + + while (ctx->hash_count < pos * 50 / ctx->content_len) { + putc('#'); + ctx->hash_count++; } return 0; @@ -234,6 +239,14 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result, return; } + /* Print hash marks for the last packet received */ + while (ctx->hash_count < 49) { + putc('#'); + ctx->hash_count++; + } + puts(" "); + print_size(ctx->content_len, ""); + elapsed = get_timer(ctx->start_time); if (!elapsed) elapsed = 1; @@ -263,11 +276,15 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result, static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len) { + struct wget_ctx *ctx = arg; + wget_lwip_fill_info(hdr, hdr_len, content_len); if (wget_info->check_buffer_size && (ulong)content_len > wget_info->buffer_size) return ERR_BUF; + ctx->content_len = content_len; + return ERR_OK; } @@ -294,6 +311,8 @@ int wget_do_request(ulong dst_addr, char *uri) ctx.size = 0; ctx.prevsize = 0; ctx.start_time = 0; + ctx.content_len = 0; + ctx.hash_count = 0; if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https)) return CMD_RET_USAGE; -- 2.47.3