mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 12:34:19 +00:00
- Delete hostname resolver asynchronously to avoid freezing the GUI on preference window closing
This commit is contained in:
parent
5962ef79cb
commit
4824637681
@ -89,7 +89,7 @@ void PeerListWidget::updatePeerHostNameResolutionState() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(resolver)
|
if(resolver)
|
||||||
delete resolver;
|
resolver->asyncDelete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,13 +47,17 @@ class ReverseResolutionST: public QThread {
|
|||||||
private:
|
private:
|
||||||
boost::asio::ip::tcp::endpoint ip;
|
boost::asio::ip::tcp::endpoint ip;
|
||||||
boost::asio::ip::tcp::resolver resolver;
|
boost::asio::ip::tcp::resolver resolver;
|
||||||
|
bool stopped;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ReverseResolutionST(boost::asio::io_service &ios, QObject *parent=0): QThread(parent), resolver(ios) {
|
ReverseResolutionST(boost::asio::io_service &ios, QObject *parent=0): QThread(parent), resolver(ios), stopped(false) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~ReverseResolutionST() {
|
~ReverseResolutionST() {
|
||||||
|
stopped = true;
|
||||||
|
if(isRunning())
|
||||||
|
resolver.cancel();
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +71,7 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
void run() {
|
void run() {
|
||||||
boost::asio::ip::tcp::resolver::iterator it = resolver.resolve(ip);
|
boost::asio::ip::tcp::resolver::iterator it = resolver.resolve(ip);
|
||||||
|
if(stopped) return;
|
||||||
qDebug("IP was resolved");
|
qDebug("IP was resolved");
|
||||||
boost::asio::ip::tcp::endpoint endpoint = *it;
|
boost::asio::ip::tcp::endpoint endpoint = *it;
|
||||||
emit ip_resolved(misc::toQString(endpoint.address().to_string()), misc::toQString((*it).host_name()));
|
emit ip_resolved(misc::toQString(endpoint.address().to_string()), misc::toQString((*it).host_name()));
|
||||||
@ -90,10 +95,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~ReverseResolution() {
|
~ReverseResolution() {
|
||||||
|
qDebug("Deleting host name resolver...");
|
||||||
|
if(!stopped) {
|
||||||
|
stopped = true;
|
||||||
|
cond.wakeOne();
|
||||||
|
}
|
||||||
|
wait();
|
||||||
|
qDebug("Host name resolver was deleted");
|
||||||
|
}
|
||||||
|
|
||||||
|
void asyncDelete() {
|
||||||
|
connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
|
||||||
|
qDebug("Deleting async host name resolver...");
|
||||||
stopped = true;
|
stopped = true;
|
||||||
cond.wakeOne();
|
cond.wakeOne();
|
||||||
qDeleteAll(subThreads);
|
|
||||||
wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void resolve(boost::asio::ip::tcp::endpoint ip) {
|
void resolve(boost::asio::ip::tcp::endpoint ip) {
|
||||||
@ -124,7 +139,10 @@ protected:
|
|||||||
do {
|
do {
|
||||||
mut.lock();
|
mut.lock();
|
||||||
cond.wait(&mut);
|
cond.wait(&mut);
|
||||||
if(stopped) return;
|
if(stopped) {
|
||||||
|
mut.unlock();
|
||||||
|
break;
|
||||||
|
}
|
||||||
boost::asio::ip::tcp::endpoint ip = ips.dequeue();
|
boost::asio::ip::tcp::endpoint ip = ips.dequeue();
|
||||||
ReverseResolutionST *st = new ReverseResolutionST(ios);
|
ReverseResolutionST *st = new ReverseResolutionST(ios);
|
||||||
subThreads.append(st);
|
subThreads.append(st);
|
||||||
@ -133,6 +151,9 @@ protected:
|
|||||||
st->setIP(ip);
|
st->setIP(ip);
|
||||||
st->start();
|
st->start();
|
||||||
}while(!stopped);
|
}while(!stopped);
|
||||||
|
mut.lock();
|
||||||
|
qDeleteAll(subThreads);
|
||||||
|
mut.unlock();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user