wok annotate busybox/stuff/busybox-1.18-wget.u @ rev 9169

Automated merge with http://hg.slitaz.org/wok
author Antoine Bodin <gokhlayeh@slitaz.org>
date Tue Mar 08 06:15:37 2011 +0100 (2011-03-08)
parents
children
rev   line source
pascal@8913 1 --- busybox-1.18.3/networking/wget.c
pascal@8913 2 +++ busybox-1.18.3-wget/networking/wget.c
pascal@8913 3 @@ -446,7 +446,7 @@ static FILE* prepare_ftp_session(FILE **
pascal@8913 4
pascal@8913 5 static void NOINLINE retrieve_file_data(FILE *dfp, int output_fd)
pascal@8913 6 {
pascal@8913 7 - char buf[512];
pascal@8913 8 + char buf[4*1024]; /* made bigger to speed up local xfers */
pascal@8913 9 #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
pascal@8913 10 # if ENABLE_FEATURE_WGET_TIMEOUT
pascal@8913 11 unsigned second_cnt;
pascal@8913 12 @@ -455,7 +455,6 @@ static void NOINLINE retrieve_file_data(
pascal@8913 13
pascal@8913 14 polldata.fd = fileno(dfp);
pascal@8913 15 polldata.events = POLLIN | POLLPRI;
pascal@8913 16 - ndelay_on(polldata.fd);
pascal@8913 17 #endif
pascal@8913 18 progress_meter(PROGRESS_START);
pascal@8913 19
pascal@8913 20 @@ -464,6 +463,10 @@ static void NOINLINE retrieve_file_data(
pascal@8913 21
pascal@8913 22 /* Loops only if chunked */
pascal@8913 23 while (1) {
pascal@8913 24 +
pascal@8913 25 +#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
pascal@8913 26 + ndelay_on(polldata.fd);
pascal@8913 27 +#endif
pascal@8913 28 while (1) {
pascal@8913 29 int n;
pascal@8913 30 unsigned rdsz;
pascal@8913 31 @@ -493,22 +496,46 @@ static void NOINLINE retrieve_file_data(
pascal@8913 32 progress_meter(PROGRESS_BUMP);
pascal@8913 33 }
pascal@8913 34 #endif
pascal@8913 35 + /* fread internally uses read loop, which in our case
pascal@8913 36 + * is usually exited when we get EAGAIN.
pascal@8913 37 + * In this case, libc sets error marker on the stream.
pascal@8913 38 + * Need to clear it before next fread to avoid possible
pascal@8913 39 + * rare false positive ferror below. Rare because usually
pascal@8913 40 + * fread gets more than zero bytes, and we don't fall
pascal@8913 41 + * into if (n <= 0) ...
pascal@8913 42 + */
pascal@8913 43 + clearerr(dfp);
pascal@8913 44 + errno = 0;
pascal@8913 45 n = safe_fread(buf, rdsz, dfp);
pascal@8913 46 + /* man fread:
pascal@8913 47 + * If error occurs, or EOF is reached, the return value
pascal@8913 48 + * is a short item count (or zero).
pascal@8913 49 + * fread does not distinguish between EOF and error.
pascal@8913 50 + */
pascal@8913 51 if (n <= 0) {
pascal@8913 52 - if (ferror(dfp)) {
pascal@8913 53 - /* perror will not work: ferror doesn't set errno */
pascal@8913 54 - bb_error_msg_and_die(bb_msg_read_error);
pascal@8913 55 - }
pascal@8913 56 - break;
pascal@8913 57 +#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
pascal@8913 58 + if (errno == EAGAIN) /* poll lied, there is no data? */
pascal@8913 59 + continue; /* yes */
pascal@8913 60 +#endif
pascal@8913 61 + if (ferror(dfp))
pascal@8913 62 + bb_perror_msg_and_die(bb_msg_read_error);
pascal@8913 63 + break; /* EOF, not error */
pascal@8913 64 }
pascal@8913 65 +
pascal@8913 66 xwrite(output_fd, buf, n);
pascal@8913 67 #if ENABLE_FEATURE_WGET_STATUSBAR
pascal@8913 68 G.transferred += n;
pascal@8913 69 progress_meter(PROGRESS_BUMP);
pascal@8913 70 #endif
pascal@8913 71 - if (G.got_clen)
pascal@8913 72 + if (G.got_clen) {
pascal@8913 73 G.content_len -= n;
pascal@8913 74 + if (G.content_len == 0)
pascal@8913 75 + break;
pascal@8913 76 + }
pascal@8913 77 }
pascal@8913 78 +#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
pascal@8913 79 + ndelay_off(polldata.fd);
pascal@8913 80 +#endif
pascal@8913 81
pascal@8913 82 if (!G.chunked)
pascal@8913 83 break;
pascal@8913 84 @@ -706,6 +733,11 @@ int wget_main(int argc UNUSED_PARAM, cha
pascal@8913 85 fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n",
pascal@8913 86 target.host, user_agent);
pascal@8913 87
pascal@8913 88 + /* Ask server to close the connection as soon as we are done
pascal@8913 89 + * (IOW: we do not intend to send more requests)
pascal@8913 90 + */
pascal@8913 91 + fprintf(sfp, "Connection: close\r\n");
pascal@8913 92 +
pascal@8913 93 #if ENABLE_FEATURE_WGET_AUTHENTICATION
pascal@8913 94 if (target.user) {
pascal@8913 95 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n"+6,
pascal@8913 96 @@ -719,22 +751,25 @@ int wget_main(int argc UNUSED_PARAM, cha
pascal@8913 97
pascal@8913 98 if (G.beg_range)
pascal@8913 99 fprintf(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range);
pascal@8913 100 +
pascal@8913 101 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
pascal@8913 102 if (extra_headers)
pascal@8913 103 fputs(extra_headers, sfp);
pascal@8913 104
pascal@8913 105 if (opt & WGET_OPT_POST_DATA) {
pascal@8913 106 char *estr = URL_escape(post_data);
pascal@8913 107 - fprintf(sfp, "Content-Type: application/x-www-form-urlencoded\r\n");
pascal@8913 108 - fprintf(sfp, "Content-Length: %u\r\n" "\r\n" "%s",
pascal@8913 109 - (int) strlen(estr), estr);
pascal@8913 110 - /*fprintf(sfp, "Connection: Keep-Alive\r\n\r\n");*/
pascal@8913 111 - /*fprintf(sfp, "%s\r\n", estr);*/
pascal@8913 112 + fprintf(sfp,
pascal@8913 113 + "Content-Type: application/x-www-form-urlencoded\r\n"
pascal@8913 114 + "Content-Length: %u\r\n"
pascal@8913 115 + "\r\n"
pascal@8913 116 + "%s",
pascal@8913 117 + (int) strlen(estr), estr
pascal@8913 118 + );
pascal@8913 119 free(estr);
pascal@8913 120 } else
pascal@8913 121 #endif
pascal@8913 122 - { /* If "Connection:" is needed, document why */
pascal@8913 123 - fprintf(sfp, /* "Connection: close\r\n" */ "\r\n");
pascal@8913 124 + {
pascal@8913 125 + fprintf(sfp, "\r\n");
pascal@8913 126 }
pascal@8913 127
pascal@8913 128 fflush(sfp);