diff options
author | Kevin Smith <git@kismith.co.uk> | 2015-09-17 18:21:44 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2015-12-17 08:58:51 (GMT) |
commit | 9bce26254aa3c2feffdd751b59cdee5e903fd2bc (patch) | |
tree | 27bf31b4564216db6bf74818dc76f0ba23af074e /Swiften/Network/BoostIOServiceThread.cpp | |
parent | bea3559998c0ae0a2afca566046f08d0a201c0b2 (diff) | |
download | swift-9bce26254aa3c2feffdd751b59cdee5e903fd2bc.zip swift-9bce26254aa3c2feffdd751b59cdee5e903fd2bc.tar.bz2 |
Add event loop for integration in Boost ASIO
This allows execution of events inside an existing io_service
if an application is already using Boost ASIO for other things
and can share the io_service.
Test-Information:
Builds on OS X 10.11.2.
Change-Id: I092ed7a25b24ef95d4664bae98ed84cc0f149073
Diffstat (limited to 'Swiften/Network/BoostIOServiceThread.cpp')
-rw-r--r-- | Swiften/Network/BoostIOServiceThread.cpp | 23 |
1 files changed, 16 insertions, 7 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(); } |