summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-12-02 23:09:55 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-12-03 08:09:01 (GMT)
commite7e514d95e190a3a7d466740a4c3a1dfa9833ccc (patch)
treefd1d70642400f5237f631a08b6f4c1b727db8160 /Swiften/Network/PlatformDomainNameServiceQuery.cpp
parent5608da36a3a319070494d5a70ff984e7c172186e (diff)
downloadswift-contrib-e7e514d95e190a3a7d466740a4c3a1dfa9833ccc.zip
swift-contrib-e7e514d95e190a3a7d466740a4c3a1dfa9833ccc.tar.bz2
Do domain resolving in a separate thread.
Diffstat (limited to 'Swiften/Network/PlatformDomainNameServiceQuery.cpp')
-rw-r--r--Swiften/Network/PlatformDomainNameServiceQuery.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.cpp b/Swiften/Network/PlatformDomainNameServiceQuery.cpp
index eeb9fd6..12afbb7 100644
--- a/Swiften/Network/PlatformDomainNameServiceQuery.cpp
+++ b/Swiften/Network/PlatformDomainNameServiceQuery.cpp
@@ -32,10 +32,25 @@ namespace {
namespace Swift {
-PlatformDomainNameServiceQuery::PlatformDomainNameServiceQuery(const String& service) : service(service) {
+PlatformDomainNameServiceQuery::PlatformDomainNameServiceQuery(const String& service) : thread(NULL), service(service), safeToJoin(true) {
+}
+
+PlatformDomainNameServiceQuery::~PlatformDomainNameServiceQuery() {
+ if (safeToJoin) {
+ thread->join();
+ }
+ else {
+ // FIXME: UGLYYYYY
+ }
+ delete thread;
}
void PlatformDomainNameServiceQuery::run() {
+ safeToJoin = false;
+ thread = new boost::thread(boost::bind(&PlatformDomainNameServiceQuery::doRun, shared_from_this()));
+}
+
+void PlatformDomainNameServiceQuery::doRun() {
std::vector<DomainNameServiceQuery::Result> records;
#if defined(SWIFTEN_PLATFORM_WINDOWS)
@@ -145,11 +160,13 @@ void PlatformDomainNameServiceQuery::run() {
}
#endif
+ safeToJoin = true;
std::sort(records.begin(), records.end(), SRVRecordPriorityComparator());
MainEventLoop::postEvent(boost::bind(boost::ref(onResult), records));
}
void PlatformDomainNameServiceQuery::emitError() {
+ safeToJoin = true;
MainEventLoop::postEvent(boost::bind(boost::ref(onResult), std::vector<DomainNameServiceQuery::Result>()), shared_from_this());
}