mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-02 09:46:37 +03:00
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 <marek.vasut+renesas@mailbox.org> Acked-by: Jerome Forissier <jerome.forissier@rm.com>
This commit is contained in:
committed by
Jerome Forissier
parent
337f50bad2
commit
68a8f0f1f3
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user