Update httpdownloader class.

This commit is contained in:
codestation
2014-04-03 15:22:19 -04:30
parent 20cd8f80a0
commit 06363de75b

View File

@@ -83,32 +83,32 @@ void HTTPDownloader::readyRead()
dataRead.lock(); dataRead.lock();
int currOffset = bufferSize; int currOffset = bufferSize;
if(bufferSize == 0) { if(bufferSize == 0) {
bufferSize = reply->bytesAvailable(); bufferSize = reply->bytesAvailable();
if(firstRead) { if(firstRead) {
bufferSize += 8; bufferSize += 8;
currOffset += 8; currOffset += 8;
}
// start with a 16KiB buffer // start with a 16KiB buffer
buffer = (char *)malloc(16384 + 2048); buffer = (char *)malloc(16384);
if(firstRead) {
*(uint64_t *)buffer = m_contentLength; *(uint64_t *)buffer = m_contentLength;
firstRead = false; firstRead = false;
} }
} else { } else {
bufferSize += reply->bytesAvailable(); bufferSize += reply->bytesAvailable();
if(bufferSize > 16384 + 2048) {
if(bufferSize > 16384) {
buffer = (char *)realloc(buffer, bufferSize); buffer = (char *)realloc(buffer, bufferSize);
} }
} }
reply->read(buffer + currOffset, reply->bytesAvailable());
reply->read(buffer + currOffset, reply->bytesAvailable());
downloadLeft -= bufferSize; downloadLeft -= bufferSize;
//qDebug("bufferSize: %li, downloadLeft: %li", bufferSize, downloadLeft); if(bufferSize >= 16384 || downloadLeft == 0) {
if(bufferSize > 16384 || downloadLeft == 0) {
dataAvailable.unlock(); dataAvailable.unlock();
} }
dataRead.unlock(); dataRead.unlock();