mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-14 08:48:17 +00:00
- Multithreaded downloadThread for performance
This commit is contained in:
parent
c086558597
commit
f4adf173a2
2
TODO
2
TODO
@ -45,9 +45,7 @@
|
|||||||
- Windows port (Chris - Peerkoel)
|
- Windows port (Chris - Peerkoel)
|
||||||
- Translations update
|
- Translations update
|
||||||
- Allow to abort a search by launching another one
|
- Allow to abort a search by launching another one
|
||||||
- Multithread downloadThread
|
|
||||||
* beta2
|
* beta2
|
||||||
- Improve RSS code + cleanup (chris)
|
|
||||||
- Wait for some bug fixes in libtorrent :
|
- Wait for some bug fixes in libtorrent :
|
||||||
- upload/download limit per torrent
|
- upload/download limit per torrent
|
||||||
- ipfilter crash
|
- ipfilter crash
|
||||||
|
@ -46,16 +46,22 @@ class downloadThread : public QThread {
|
|||||||
QWaitCondition condition;
|
QWaitCondition condition;
|
||||||
bool abort;
|
bool abort;
|
||||||
URLStream url_stream;
|
URLStream url_stream;
|
||||||
|
QList<downloadThread*> subThreads;
|
||||||
|
bool subThread;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void downloadFinished(QString url, QString file_path);
|
void downloadFinished(QString url, QString file_path);
|
||||||
void downloadFailure(QString url, QString reason);
|
void downloadFailure(QString url, QString reason);
|
||||||
|
// For subthreads
|
||||||
|
void downloadFinishedST(downloadThread* st, QString url, QString file_path);
|
||||||
|
void downloadFailureST(downloadThread* st, QString url, QString reason);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
downloadThread(QObject* parent) : QThread(parent){
|
downloadThread(QObject* parent, bool subThread = false) : QThread(parent){
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
abort = false;
|
abort = false;
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
this->subThread = subThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
~downloadThread(){
|
~downloadThread(){
|
||||||
@ -112,6 +118,15 @@ class downloadThread : public QThread {
|
|||||||
if(url_list.size() != 0){
|
if(url_list.size() != 0){
|
||||||
QString url = url_list.takeFirst();
|
QString url = url_list.takeFirst();
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
if(!subThread){
|
||||||
|
downloadThread *st = new downloadThread(0, true);
|
||||||
|
subThreads << st;
|
||||||
|
connect(st, SIGNAL(downloadFinishedST(downloadThread*, QString, QString)), this, SLOT(propagateDownloadedFile(downloadThread*, QString, QString)));
|
||||||
|
connect(st, SIGNAL(downloadFailureST(downloadThread*, QString, QString)), this, SLOT(propagateDownloadFailure(downloadThread*, QString, QString)));
|
||||||
|
st->downloadUrl(url);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Sub threads code
|
||||||
// XXX: Trick to get a unique filename
|
// XXX: Trick to get a unique filename
|
||||||
QString filePath;
|
QString filePath;
|
||||||
QTemporaryFile *tmpfile = new QTemporaryFile();
|
QTemporaryFile *tmpfile = new QTemporaryFile();
|
||||||
@ -130,7 +145,7 @@ class downloadThread : public QThread {
|
|||||||
QString error_msg = QString(misc::toString(status).c_str());
|
QString error_msg = QString(misc::toString(status).c_str());
|
||||||
qDebug("Download failed for %s, reason: %s", (const char*)url.toUtf8(), (const char*)error_msg.toUtf8());
|
qDebug("Download failed for %s, reason: %s", (const char*)url.toUtf8(), (const char*)error_msg.toUtf8());
|
||||||
url_stream.close();
|
url_stream.close();
|
||||||
emit downloadFailure(url, errorCodeToString(status));
|
emit downloadFailureST(this, url, errorCodeToString(status));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
qDebug("Downloading %s...", (const char*)url.toUtf8());
|
qDebug("Downloading %s...", (const char*)url.toUtf8());
|
||||||
@ -149,7 +164,7 @@ class downloadThread : public QThread {
|
|||||||
}
|
}
|
||||||
dest_file.close();
|
dest_file.close();
|
||||||
url_stream.close();
|
url_stream.close();
|
||||||
emit downloadFinished(url, filePath);
|
emit downloadFinishedST(this, url, filePath);
|
||||||
qDebug("download completed here: %s", (const char*)filePath.toUtf8());
|
qDebug("download completed here: %s", (const char*)filePath.toUtf8());
|
||||||
}else{
|
}else{
|
||||||
condition.wait(&mutex);
|
condition.wait(&mutex);
|
||||||
@ -157,6 +172,26 @@ class downloadThread : public QThread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected slots:
|
||||||
|
void propagateDownloadedFile(downloadThread* st, QString url, QString path){
|
||||||
|
int index = subThreads.indexOf(st);
|
||||||
|
if(index == -1)
|
||||||
|
std::cerr << "ERROR: Couldn't delete download subThread!\n";
|
||||||
|
else
|
||||||
|
subThreads.takeAt(index);
|
||||||
|
delete st;
|
||||||
|
emit downloadFinished(url, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void propagateDownloadFailure(downloadThread* st, QString url, QString reason){
|
||||||
|
int index = subThreads.indexOf(st);
|
||||||
|
if(index == -1)
|
||||||
|
std::cerr << "ERROR: Couldn't delete download subThread!\n";
|
||||||
|
else
|
||||||
|
subThreads.takeAt(index);
|
||||||
|
delete st;
|
||||||
|
emit downloadFailure(url, reason);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user