summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-12-18 18:50:50 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-12-18 18:50:50 (GMT)
commit312a114c7e204cfe4cfe961509ab9b24ccde7860 (patch)
tree7649aba8b50de49f5259709ee3d34b035d83b33b /Swiften/Network/PlatformDomainNameServiceQuery.cpp
parent790dd3e97c6634f6a256f2e072507b9d5f29348b (diff)
downloadswift-312a114c7e204cfe4cfe961509ab9b24ccde7860.zip
swift-312a114c7e204cfe4cfe961509ab9b24ccde7860.tar.bz2
Move all domain name resolve queries into one thread.
This avoids reentrancy problems on some platform DNS calls. Resolves: #443
Diffstat (limited to 'Swiften/Network/PlatformDomainNameServiceQuery.cpp')
-rw-r--r--Swiften/Network/PlatformDomainNameServiceQuery.cpp20
1 files changed, 4 insertions, 16 deletions
diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.cpp b/Swiften/Network/PlatformDomainNameServiceQuery.cpp
index 7ab6e7a..bdbb664 100644
--- a/Swiften/Network/PlatformDomainNameServiceQuery.cpp
+++ b/Swiften/Network/PlatformDomainNameServiceQuery.cpp
@@ -28,30 +28,20 @@
#include "Swiften/EventLoop/EventLoop.h"
#include "Swiften/Base/foreach.h"
#include <Swiften/Base/Log.h>
+#include <Swiften/Network/PlatformDomainNameResolver.h>
using namespace Swift;
namespace Swift {
-PlatformDomainNameServiceQuery::PlatformDomainNameServiceQuery(const String& service, EventLoop* eventLoop) : eventLoop(eventLoop), thread(NULL), service(service), safeToJoin(true) {
-}
-
-PlatformDomainNameServiceQuery::~PlatformDomainNameServiceQuery() {
- if (safeToJoin) {
- thread->join();
- }
- else {
- // FIXME: UGLYYYYY
- }
- delete thread;
+PlatformDomainNameServiceQuery::PlatformDomainNameServiceQuery(const String& service, EventLoop* eventLoop, PlatformDomainNameResolver* resolver) : PlatformDomainNameQuery(resolver), eventLoop(eventLoop), service(service) {
}
void PlatformDomainNameServiceQuery::run() {
- safeToJoin = false;
- thread = new boost::thread(boost::bind(&PlatformDomainNameServiceQuery::doRun, shared_from_this()));
+ getResolver()->addQueryToQueue(shared_from_this());
}
-void PlatformDomainNameServiceQuery::doRun() {
+void PlatformDomainNameServiceQuery::runBlocking() {
SWIFT_LOG(debug) << "Querying " << service << std::endl;
std::vector<DomainNameServiceQuery::Result> records;
@@ -166,14 +156,12 @@ void PlatformDomainNameServiceQuery::doRun() {
}
#endif
- safeToJoin = true;
std::sort(records.begin(), records.end(), ResultPriorityComparator());
//std::cout << "Sending out " << records.size() << " SRV results " << std::endl;
eventLoop->postEvent(boost::bind(boost::ref(onResult), records));
}
void PlatformDomainNameServiceQuery::emitError() {
- safeToJoin = true;
eventLoop->postEvent(boost::bind(boost::ref(onResult), std::vector<DomainNameServiceQuery::Result>()), shared_from_this());
}