Ignore:
Timestamp:
Jul 26, 2011, 1:25:42 AM (8 years ago)
Author:
bruno
Message:
  • Update to upstream busybox 1.18.5
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/networking/wget.c

    r2725 r2859  
    447447static void NOINLINE retrieve_file_data(FILE *dfp, int output_fd)
    448448{
    449     char buf[512];
     449    char buf[4*1024]; /* made bigger to speed up local xfers */
    450450#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
    451451# if ENABLE_FEATURE_WGET_TIMEOUT
     
    456456    polldata.fd = fileno(dfp);
    457457    polldata.events = POLLIN | POLLPRI;
    458     ndelay_on(polldata.fd);
    459458#endif
    460459    progress_meter(PROGRESS_START);
     
    465464    /* Loops only if chunked */
    466465    while (1) {
     466
     467#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
     468        ndelay_on(polldata.fd);
     469#endif
    467470        while (1) {
    468471            int n;
     
    494497            }
    495498#endif
     499            /* fread internally uses read loop, which in our case
     500             * is usually exited when we get EAGAIN.
     501             * In this case, libc sets error marker on the stream.
     502             * Need to clear it before next fread to avoid possible
     503             * rare false positive ferror below. Rare because usually
     504             * fread gets more than zero bytes, and we don't fall
     505             * into if (n <= 0) ...
     506             */
     507            clearerr(dfp);
     508            errno = 0;
    496509            n = safe_fread(buf, rdsz, dfp);
     510            /* man fread:
     511             * If error occurs, or EOF is reached, the return value
     512             * is a short item count (or zero).
     513             * fread does not distinguish between EOF and error.
     514             */
    497515            if (n <= 0) {
    498                 if (ferror(dfp)) {
    499                     /* perror will not work: ferror doesn't set errno */
    500                     bb_error_msg_and_die(bb_msg_read_error);
    501                 }
    502                 break;
     516#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
     517                if (errno == EAGAIN) /* poll lied, there is no data? */
     518                    continue; /* yes */
     519#endif
     520                if (ferror(dfp))
     521                    bb_perror_msg_and_die(bb_msg_read_error);
     522                break; /* EOF, not error */
    503523            }
     524
    504525            xwrite(output_fd, buf, n);
    505526#if ENABLE_FEATURE_WGET_STATUSBAR
     
    507528            progress_meter(PROGRESS_BUMP);
    508529#endif
    509             if (G.got_clen)
     530            if (G.got_clen) {
    510531                G.content_len -= n;
    511         }
     532                if (G.content_len == 0)
     533                    break;
     534            }
     535        }
     536#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
     537        ndelay_off(polldata.fd);
     538#endif
    512539
    513540        if (!G.chunked)
     
    707734            target.host, user_agent);
    708735
     736        /* Ask server to close the connection as soon as we are done
     737         * (IOW: we do not intend to send more requests)
     738         */
     739        fprintf(sfp, "Connection: close\r\n");
     740
    709741#if ENABLE_FEATURE_WGET_AUTHENTICATION
    710742        if (target.user) {
     
    720752        if (G.beg_range)
    721753            fprintf(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range);
     754
    722755#if ENABLE_FEATURE_WGET_LONG_OPTIONS
    723756        if (extra_headers)
     
    726759        if (opt & WGET_OPT_POST_DATA) {
    727760            char *estr = URL_escape(post_data);
    728             fprintf(sfp, "Content-Type: application/x-www-form-urlencoded\r\n");
    729             fprintf(sfp, "Content-Length: %u\r\n" "\r\n" "%s",
    730                     (int) strlen(estr), estr);
    731             /*fprintf(sfp, "Connection: Keep-Alive\r\n\r\n");*/
    732             /*fprintf(sfp, "%s\r\n", estr);*/
     761            fprintf(sfp,
     762                "Content-Type: application/x-www-form-urlencoded\r\n"
     763                "Content-Length: %u\r\n"
     764                "\r\n"
     765                "%s",
     766                (int) strlen(estr), estr
     767            );
    733768            free(estr);
    734769        } else
    735770#endif
    736         { /* If "Connection:" is needed, document why */
    737             fprintf(sfp, /* "Connection: close\r\n" */ "\r\n");
     771        {
     772            fprintf(sfp, "\r\n");
    738773        }
    739774
Note: See TracChangeset for help on using the changeset viewer.