diff options
Diffstat (limited to 'Swiften/Network')
-rw-r--r-- | Swiften/Network/BoostIOServiceThread.cpp | 23 | ||||
-rw-r--r-- | Swiften/Network/BoostIOServiceThread.h | 12 | ||||
-rw-r--r-- | Swiften/Network/BoostNetworkFactories.cpp | 22 | ||||
-rw-r--r-- | Swiften/Network/BoostNetworkFactories.h | 9 |
4 files changed, 44 insertions, 22 deletions
diff --git a/Swiften/Network/BoostIOServiceThread.cpp b/Swiften/Network/BoostIOServiceThread.cpp index 6a89c9a..57b2cb4 100644 --- a/Swiften/Network/BoostIOServiceThread.cpp +++ b/Swiften/Network/BoostIOServiceThread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -10,18 +10,27 @@ namespace Swift { -BoostIOServiceThread::BoostIOServiceThread() { - ioService_ = boost::make_shared<boost::asio::io_service>(); - thread_ = new boost::thread(boost::bind(&BoostIOServiceThread::doRun, this)); +BoostIOServiceThread::BoostIOServiceThread(boost::shared_ptr<boost::asio::io_service> ioService) { + if (!!ioService) { + ioService_ = ioService; + thread_ = NULL; + } + else { + ioService_ = boost::make_shared<boost::asio::io_service>(); + thread_ = new boost::thread(boost::bind(&BoostIOServiceThread::doRun, this)); + } } BoostIOServiceThread::~BoostIOServiceThread() { - ioService_->stop(); - thread_->join(); - delete thread_; + if (thread_) { + ioService_->stop(); + thread_->join(); + delete thread_; + } } void BoostIOServiceThread::doRun() { + assert(thread_); boost::asio::io_service::work work(*ioService_); ioService_->run(); } diff --git a/Swiften/Network/BoostIOServiceThread.h b/Swiften/Network/BoostIOServiceThread.h index 37047d1..428837b 100644 --- a/Swiften/Network/BoostIOServiceThread.h +++ b/Swiften/Network/BoostIOServiceThread.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -15,7 +15,15 @@ namespace Swift { class SWIFTEN_API BoostIOServiceThread { public: - BoostIOServiceThread(); + /** + * Construct the object. + * @param ioService If this optional parameter is provided, the behaviour + * of this class changes completely - it no longer spawns its own thread + * and instead acts as a simple wrapper of the io_service. Use this if + * you are re-using an io_service from elsewhere (particularly if you + * are using the BoostASIOEventLoop). + */ + BoostIOServiceThread(boost::shared_ptr<boost::asio::io_service> ioService = boost::shared_ptr<boost::asio::io_service>()); ~BoostIOServiceThread(); boost::shared_ptr<boost::asio::io_service> getIOService() const { diff --git a/Swiften/Network/BoostNetworkFactories.cpp b/Swiften/Network/BoostNetworkFactories.cpp index 4ab42d9..871a38b 100644 --- a/Swiften/Network/BoostNetworkFactories.cpp +++ b/Swiften/Network/BoostNetworkFactories.cpp @@ -1,24 +1,24 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/BoostNetworkFactories.h> -#include <Swiften/Network/BoostTimerFactory.h> -#include <Swiften/Network/BoostConnectionFactory.h> +#include <Swiften/Crypto/CryptoProvider.h> +#include <Swiften/Crypto/PlatformCryptoProvider.h> +#include <Swiften/IDN/IDNConverter.h> +#include <Swiften/IDN/PlatformIDNConverter.h> +#include <Swiften/Network/BoostConnectionFactory.h> #include <Swiften/Network/BoostConnectionServerFactory.h> -#include <Swiften/Network/PlatformNATTraversalWorker.h> -#include <Swiften/Parser/PlatformXMLParserFactory.h> +#include <Swiften/Network/BoostTimerFactory.h> #include <Swiften/Network/NullNATTraverser.h> +#include <Swiften/Network/PlatformNATTraversalWorker.h> #include <Swiften/Network/PlatformNetworkEnvironment.h> -#include <Swiften/TLS/PlatformTLSFactories.h> #include <Swiften/Network/PlatformProxyProvider.h> -#include <Swiften/IDN/PlatformIDNConverter.h> -#include <Swiften/IDN/IDNConverter.h> -#include <Swiften/Crypto/PlatformCryptoProvider.h> -#include <Swiften/Crypto/CryptoProvider.h> +#include <Swiften/Parser/PlatformXMLParserFactory.h> +#include <Swiften/TLS/PlatformTLSFactories.h> #ifdef USE_UNBOUND #include <Swiften/Network/UnboundDomainNameResolver.h> @@ -28,7 +28,7 @@ namespace Swift { -BoostNetworkFactories::BoostNetworkFactories(EventLoop* eventLoop) : eventLoop(eventLoop){ +BoostNetworkFactories::BoostNetworkFactories(EventLoop* eventLoop, boost::shared_ptr<boost::asio::io_service> ioService) : ioServiceThread(ioService), eventLoop(eventLoop) { timerFactory = new BoostTimerFactory(ioServiceThread.getIOService(), eventLoop); connectionFactory = new BoostConnectionFactory(ioServiceThread.getIOService(), eventLoop); connectionServerFactory = new BoostConnectionServerFactory(ioServiceThread.getIOService(), eventLoop); diff --git a/Swiften/Network/BoostNetworkFactories.h b/Swiften/Network/BoostNetworkFactories.h index 32fdd93..12755b9 100644 --- a/Swiften/Network/BoostNetworkFactories.h +++ b/Swiften/Network/BoostNetworkFactories.h @@ -8,8 +8,8 @@ #include <Swiften/Base/API.h> #include <Swiften/Base/Override.h> -#include <Swiften/Network/NetworkFactories.h> #include <Swiften/Network/BoostIOServiceThread.h> +#include <Swiften/Network/NetworkFactories.h> namespace Swift { class EventLoop; @@ -18,7 +18,12 @@ namespace Swift { class SWIFTEN_API BoostNetworkFactories : public NetworkFactories { public: - BoostNetworkFactories(EventLoop* eventLoop); + /** + * Construct the network factories, using the provided EventLoop. + * @param ioService If this optional parameter is provided, it will be + * used for the construction of the BoostIOServiceThread. + */ + BoostNetworkFactories(EventLoop* eventLoop, boost::shared_ptr<boost::asio::io_service> ioService = boost::shared_ptr<boost::asio::io_service>()); virtual ~BoostNetworkFactories(); virtual TimerFactory* getTimerFactory() const SWIFTEN_OVERRIDE { |