wok-6.x diff busybox/stuff/busybox-1.18-wget.u @ rev 8913

busybox: wget speedup
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Feb 28 15:05:05 2011 +0100 (2011-02-28)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/busybox/stuff/busybox-1.18-wget.u	Mon Feb 28 15:05:05 2011 +0100
     1.3 @@ -0,0 +1,128 @@
     1.4 +--- busybox-1.18.3/networking/wget.c
     1.5 ++++ busybox-1.18.3-wget/networking/wget.c
     1.6 +@@ -446,7 +446,7 @@ static FILE* prepare_ftp_session(FILE **
     1.7 + 
     1.8 + static void NOINLINE retrieve_file_data(FILE *dfp, int output_fd)
     1.9 + {
    1.10 +-	char buf[512];
    1.11 ++	char buf[4*1024]; /* made bigger to speed up local xfers */
    1.12 + #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
    1.13 + # if ENABLE_FEATURE_WGET_TIMEOUT
    1.14 + 	unsigned second_cnt;
    1.15 +@@ -455,7 +455,6 @@ static void NOINLINE retrieve_file_data(
    1.16 + 
    1.17 + 	polldata.fd = fileno(dfp);
    1.18 + 	polldata.events = POLLIN | POLLPRI;
    1.19 +-	ndelay_on(polldata.fd);
    1.20 + #endif
    1.21 + 	progress_meter(PROGRESS_START);
    1.22 + 
    1.23 +@@ -464,6 +463,10 @@ static void NOINLINE retrieve_file_data(
    1.24 + 
    1.25 + 	/* Loops only if chunked */
    1.26 + 	while (1) {
    1.27 ++
    1.28 ++#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
    1.29 ++		ndelay_on(polldata.fd);
    1.30 ++#endif
    1.31 + 		while (1) {
    1.32 + 			int n;
    1.33 + 			unsigned rdsz;
    1.34 +@@ -493,22 +496,46 @@ static void NOINLINE retrieve_file_data(
    1.35 + 				progress_meter(PROGRESS_BUMP);
    1.36 + 			}
    1.37 + #endif
    1.38 ++			/* fread internally uses read loop, which in our case
    1.39 ++			 * is usually exited when we get EAGAIN.
    1.40 ++			 * In this case, libc sets error marker on the stream.
    1.41 ++			 * Need to clear it before next fread to avoid possible
    1.42 ++			 * rare false positive ferror below. Rare because usually
    1.43 ++			 * fread gets more than zero bytes, and we don't fall
    1.44 ++			 * into if (n <= 0) ...
    1.45 ++			 */
    1.46 ++			clearerr(dfp);
    1.47 ++			errno = 0;
    1.48 + 			n = safe_fread(buf, rdsz, dfp);
    1.49 ++			/* man fread:
    1.50 ++			 * If error occurs, or EOF is reached, the return value
    1.51 ++			 * is a short item count (or zero).
    1.52 ++			 * fread does not distinguish between EOF and error.
    1.53 ++			 */
    1.54 + 			if (n <= 0) {
    1.55 +-				if (ferror(dfp)) {
    1.56 +-					/* perror will not work: ferror doesn't set errno */
    1.57 +-					bb_error_msg_and_die(bb_msg_read_error);
    1.58 +-				}
    1.59 +-				break;
    1.60 ++#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
    1.61 ++				if (errno == EAGAIN) /* poll lied, there is no data? */
    1.62 ++					continue; /* yes */
    1.63 ++#endif
    1.64 ++				if (ferror(dfp))
    1.65 ++					bb_perror_msg_and_die(bb_msg_read_error);
    1.66 ++				break; /* EOF, not error */
    1.67 + 			}
    1.68 ++
    1.69 + 			xwrite(output_fd, buf, n);
    1.70 + #if ENABLE_FEATURE_WGET_STATUSBAR
    1.71 + 			G.transferred += n;
    1.72 + 			progress_meter(PROGRESS_BUMP);
    1.73 + #endif
    1.74 +-			if (G.got_clen)
    1.75 ++			if (G.got_clen) {
    1.76 + 				G.content_len -= n;
    1.77 ++				if (G.content_len == 0)
    1.78 ++					break;
    1.79 ++			}
    1.80 + 		}
    1.81 ++#if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
    1.82 ++		ndelay_off(polldata.fd);
    1.83 ++#endif
    1.84 + 
    1.85 + 		if (!G.chunked)
    1.86 + 			break;
    1.87 +@@ -706,6 +733,11 @@ int wget_main(int argc UNUSED_PARAM, cha
    1.88 + 		fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n",
    1.89 + 			target.host, user_agent);
    1.90 + 
    1.91 ++		/* Ask server to close the connection as soon as we are done
    1.92 ++		 * (IOW: we do not intend to send more requests)
    1.93 ++		 */
    1.94 ++		fprintf(sfp, "Connection: close\r\n");
    1.95 ++
    1.96 + #if ENABLE_FEATURE_WGET_AUTHENTICATION
    1.97 + 		if (target.user) {
    1.98 + 			fprintf(sfp, "Proxy-Authorization: Basic %s\r\n"+6,
    1.99 +@@ -719,22 +751,25 @@ int wget_main(int argc UNUSED_PARAM, cha
   1.100 + 
   1.101 + 		if (G.beg_range)
   1.102 + 			fprintf(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range);
   1.103 ++
   1.104 + #if ENABLE_FEATURE_WGET_LONG_OPTIONS
   1.105 + 		if (extra_headers)
   1.106 + 			fputs(extra_headers, sfp);
   1.107 + 
   1.108 + 		if (opt & WGET_OPT_POST_DATA) {
   1.109 + 			char *estr = URL_escape(post_data);
   1.110 +-			fprintf(sfp, "Content-Type: application/x-www-form-urlencoded\r\n");
   1.111 +-			fprintf(sfp, "Content-Length: %u\r\n" "\r\n" "%s",
   1.112 +-					(int) strlen(estr), estr);
   1.113 +-			/*fprintf(sfp, "Connection: Keep-Alive\r\n\r\n");*/
   1.114 +-			/*fprintf(sfp, "%s\r\n", estr);*/
   1.115 ++			fprintf(sfp,
   1.116 ++				"Content-Type: application/x-www-form-urlencoded\r\n"
   1.117 ++				"Content-Length: %u\r\n"
   1.118 ++				"\r\n"
   1.119 ++				"%s",
   1.120 ++				(int) strlen(estr), estr
   1.121 ++			);
   1.122 + 			free(estr);
   1.123 + 		} else
   1.124 + #endif
   1.125 +-		{ /* If "Connection:" is needed, document why */
   1.126 +-			fprintf(sfp, /* "Connection: close\r\n" */ "\r\n");
   1.127 ++		{
   1.128 ++			fprintf(sfp, "\r\n");
   1.129 + 		}
   1.130 + 
   1.131 + 		fflush(sfp);