summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorMarek Vasut <[email protected]>2026-01-29 01:23:29 +0100
committerJerome Forissier <[email protected]>2026-02-06 16:42:45 +0100
commit68a8f0f1f34dde836609bf34506d32bfdb2b1f6e (patch)
treea9b8e4b21ebd0ae3eb8542ef3b2fdb8c28871951 /net
parent337f50bad2ac8e1db126e4f6d372a3186bba2893 (diff)
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 <[email protected]> Acked-by: Jerome Forissier <[email protected]>
Diffstat (limited to 'net')
-rw-r--r--net/lwip/wget.c27
1 files 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;