"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Marek Vasut and committed by
Jerome Forissier
68a8f0f1 337f50ba

+23 -4
+23 -4
net/lwip/wget.c
··· 37 37 ulong size; 38 38 ulong prevsize; 39 39 ulong start_time; 40 + ulong content_len; 41 + ulong hash_count; 40 42 enum done_state done; 41 43 }; 42 44 ··· 152 154 { 153 155 ulong store_addr = ctx->daddr; 154 156 uchar *ptr; 157 + ulong pos; 155 158 156 159 /* Avoid overflow */ 157 160 if (wget_info->buffer_size && wget_info->buffer_size < ctx->size + len) ··· 174 177 175 178 ctx->daddr += len; 176 179 ctx->size += len; 177 - if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { 178 - if (!wget_info->silent) 179 - printf("#"); 180 - ctx->prevsize = ctx->size; 180 + 181 + pos = clamp(ctx->size, 0UL, ctx->content_len); 182 + 183 + while (ctx->hash_count < pos * 50 / ctx->content_len) { 184 + putc('#'); 185 + ctx->hash_count++; 181 186 } 182 187 183 188 return 0; ··· 234 239 return; 235 240 } 236 241 242 + /* Print hash marks for the last packet received */ 243 + while (ctx->hash_count < 49) { 244 + putc('#'); 245 + ctx->hash_count++; 246 + } 247 + puts(" "); 248 + print_size(ctx->content_len, ""); 249 + 237 250 elapsed = get_timer(ctx->start_time); 238 251 if (!elapsed) 239 252 elapsed = 1; ··· 263 276 static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct pbuf *hdr, 264 277 u16_t hdr_len, u32_t content_len) 265 278 { 279 + struct wget_ctx *ctx = arg; 280 + 266 281 wget_lwip_fill_info(hdr, hdr_len, content_len); 267 282 268 283 if (wget_info->check_buffer_size && (ulong)content_len > wget_info->buffer_size) 269 284 return ERR_BUF; 285 + 286 + ctx->content_len = content_len; 270 287 271 288 return ERR_OK; 272 289 } ··· 294 311 ctx.size = 0; 295 312 ctx.prevsize = 0; 296 313 ctx.start_time = 0; 314 + ctx.content_len = 0; 315 + ctx.hash_count = 0; 297 316 298 317 if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https)) 299 318 return CMD_RET_USAGE;