summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath2003-08-28 21:55:22 +0000
committerGlenn L McGrath2003-08-28 21:55:22 +0000
commit83e4a5bccf3b06f9b2cbd708d48d1ea0602297c6 (patch)
tree459bcd4f0aca9d75f883b91130fd4236e06b6d5c
parent8b96b7169d0af8c1b7ede14755a8bd4492f894d0 (diff)
downloadbusybox-83e4a5bccf3b06f9b2cbd708d48d1ea0602297c6.zip
busybox-83e4a5bccf3b06f9b2cbd708d48d1ea0602297c6.tar.gz
"When the filesize is known from content-length header, safe_fread is
always told to read sizeof(buf). This waits until the underlying fread() to time-out for the last part of the downloaded body. Fix this by sending the number of remaining bytes to read when known." - junkio@ I reworked the logic in his patch
-rw-r--r--networking/wget.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/networking/wget.c b/networking/wget.c
index a9ead7f..586a7e0 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -481,25 +481,30 @@ read_response: if (fgets(buf, sizeof(buf), sfp) == NULL)
progressmeter(-1);
#endif
do {
- while ((filesize > 0 || !got_clen) && (n = safe_fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) {
- if (safe_fwrite(buf, 1, n, output) != n)
+ while ((filesize > 0 || !got_clen) && (n = safe_fread(buf, 1, (chunked || !got_clen || (filesize > sizeof(buf)) ? sizeof(buf) : filesize), dfp)) > 0) {
+ if (safe_fwrite(buf, 1, n, output) != n) {
bb_perror_msg_and_die("write error");
+ }
#ifdef CONFIG_FEATURE_WGET_STATUSBAR
- statbytes+=n;
+ statbytes+=n;
#endif
- if (got_clen)
- filesize -= n;
- }
+ if (got_clen) {
+ filesize -= n;
+ }
+ }
if (chunked) {
safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */
safe_fgets(buf, sizeof(buf), dfp);
filesize = strtol(buf, (char **) NULL, 16);
- if (filesize==0) chunked = 0; /* all done! */
+ if (filesize==0) {
+ chunked = 0; /* all done! */
+ }
}
- if (n == 0 && ferror(dfp))
- bb_perror_msg_and_die("network read error");
+ if (n == 0 && ferror(dfp)) {
+ bb_perror_msg_and_die("network read error");
+ }
} while (chunked);
#ifdef CONFIG_FEATURE_WGET_STATUSBAR
if (quiet_flag==FALSE)
@@ -811,7 +816,7 @@ progressmeter(int flag)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: wget.c,v 1.54 2003/07/22 08:56:51 andersen Exp $
+ * $Id: wget.c,v 1.55 2003/08/28 21:55:22 bug1 Exp $
*/
@@ -823,6 +828,3 @@ c-basic-offset: 4
tab-width: 4
End:
*/
-
-
-