Skip to content

Commit

Permalink
Limit the network buffer memory size
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Briza committed Nov 2, 2016
1 parent 26977f2 commit 68f0ec4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ void Download::handleNewReply(QNetworkReply *reply) {
if (m_reply)
m_reply->deleteLater();
m_reply = reply;
// have only a 64MB buffer in case the user is on a very fast network
m_reply->setReadBufferSize(64*1024*1024);

connect(m_reply, &QNetworkReply::readyRead, this, &Download::onReadyRead);
connect(m_reply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &Download::onError);
Expand Down Expand Up @@ -331,15 +333,21 @@ void Download::onFinished() {
if (m_file) {
m_file->rename(m_path); // move the .part file to the final path
m_receiver->onFileDownloaded(m_file->fileName(), m_hash.result().toHex());
m_reply->deleteLater();
m_reply = nullptr;
deleteLater();
}
else {
m_receiver->onStringDownloaded(m_buf);
m_reply->deleteLater();
m_reply = nullptr;
deleteLater();
}
}
}

void Download::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
Q_UNUSED(bytesReceived);
Q_UNUSED(bytesTotal);
/*
m_bytesDownloaded = m_previousSize + bytesReceived;
Expand Down

0 comments on commit 68f0ec4

Please sign in to comment.