--- setup/geturl.cc 2008-02-22 01:03:58.000000000 +0100 +++ setup.cntlmfix/geturl.cc 2012-08-11 17:16:29.046875000 +0200 @@ -122,9 +122,14 @@ log (LOG_BABBLE) << "getUrlToStream failed!" << endLog; throw new Exception (TOSTRING(__LINE__) " " __FILE__, "Error opening url", APPERR_IO_ERROR); } + unsigned int outstanding = 0; + if (n->file_size) // Content-Length + { + max_bytes = n->file_size; + outstanding = n->file_size; + log (LOG_BABBLE) << "getUrlToStream " << "Content-Length: " << max_bytes << endLog; + } - if (n->file_size) - max_bytes = n->file_size; int total_bytes = 0; progress (0); @@ -132,13 +137,27 @@ { char buf[2048]; ssize_t rlen, wlen; - rlen = n->read (buf, 2048); + if (n->file_size) + { + if (outstanding==0) + break; + rlen = n->read(buf,min(sizeof buf,outstanding)); + outstanding -= rlen; + } + else + { + rlen = n->read (buf, sizeof buf); + } + if (rlen > 0) { wlen = output->write (buf, rlen); if (wlen != rlen) - /* FIXME: Show an error message */ - break; + { + /* FIXME: Show an error message */ + log (LOG_BABBLE) << "getUrlToStream unable to write" << endLog; + break; + } total_bytes += rlen; progress (total_bytes); } @@ -233,9 +252,12 @@ err = "(unknown error)"; fatal (owner, IDS_ERR_OPEN_WRITE, _filename.c_str(), err); } - + unsigned int outstanding = 0; if (n->file_size) - max_bytes = n->file_size; + { + max_bytes = n->file_size; + outstanding = max_bytes; + } int total_bytes = 0; progress (0); @@ -243,7 +265,17 @@ { char buf[8192]; int count; - count = n->read (buf, sizeof (buf)); + if (n->file_size) + { + if (outstanding==0) + break; + count = n->read (buf, min(sizeof buf,outstanding)); + outstanding-=count; + } + else + { + count = n->read (buf, sizeof buf); + } if (count <= 0) break; fwrite (buf, 1, count, f);