summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/BoostConnection.cpp4
-rw-r--r--Swiften/Network/BoostConnection.h5
-rw-r--r--Swiften/Network/BoostConnectionFactory.cpp2
-rw-r--r--Swiften/Network/BoostConnectionFactory.h4
-rw-r--r--Swiften/Network/BoostConnectionServer.cpp4
-rw-r--r--Swiften/Network/BoostConnectionServer.h6
-rw-r--r--Swiften/Network/BoostIOServiceThread.cpp15
-rw-r--r--Swiften/Network/BoostIOServiceThread.h7
-rw-r--r--Swiften/Network/BoostNetworkFactories.cpp4
-rw-r--r--Swiften/Network/BoostTimer.cpp4
-rw-r--r--Swiften/Network/BoostTimer.h5
-rw-r--r--Swiften/Network/BoostTimerFactory.cpp2
-rw-r--r--Swiften/Network/BoostTimerFactory.h4
13 files changed, 37 insertions, 29 deletions
diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp
index bba2c07..908585d 100644
--- a/Swiften/Network/BoostConnection.cpp
+++ b/Swiften/Network/BoostConnection.cpp
@@ -44,8 +44,8 @@ class SharedBuffer {
// -----------------------------------------------------------------------------
-BoostConnection::BoostConnection(boost::asio::io_service* ioService, EventLoop* eventLoop) :
- eventLoop(eventLoop), socket_(*ioService), readBuffer_(BUFFER_SIZE), writing_(false) {
+BoostConnection::BoostConnection(boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) :
+ eventLoop(eventLoop), ioService(ioService), socket_(*ioService), readBuffer_(BUFFER_SIZE), writing_(false) {
}
BoostConnection::~BoostConnection() {
diff --git a/Swiften/Network/BoostConnection.h b/Swiften/Network/BoostConnection.h
index 7b15966..506eedf 100644
--- a/Swiften/Network/BoostConnection.h
+++ b/Swiften/Network/BoostConnection.h
@@ -29,7 +29,7 @@ namespace Swift {
~BoostConnection();
- static ref create(boost::asio::io_service* ioService, EventLoop* eventLoop) {
+ static ref create(boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) {
return ref(new BoostConnection(ioService, eventLoop));
}
@@ -45,7 +45,7 @@ namespace Swift {
HostAddressPort getLocalAddress() const;
private:
- BoostConnection(boost::asio::io_service* ioService, EventLoop* eventLoop);
+ BoostConnection(boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop);
void handleConnectFinished(const boost::system::error_code& error);
void handleSocketRead(const boost::system::error_code& error, size_t bytesTransferred);
@@ -55,6 +55,7 @@ namespace Swift {
private:
EventLoop* eventLoop;
+ boost::shared_ptr<boost::asio::io_service> ioService;
boost::asio::ip::tcp::socket socket_;
std::vector<char> readBuffer_;
boost::mutex writeMutex_;
diff --git a/Swiften/Network/BoostConnectionFactory.cpp b/Swiften/Network/BoostConnectionFactory.cpp
index 00b36c6..743bb61 100644
--- a/Swiften/Network/BoostConnectionFactory.cpp
+++ b/Swiften/Network/BoostConnectionFactory.cpp
@@ -9,7 +9,7 @@
namespace Swift {
-BoostConnectionFactory::BoostConnectionFactory(boost::asio::io_service* ioService, EventLoop* eventLoop) : ioService(ioService), eventLoop(eventLoop) {
+BoostConnectionFactory::BoostConnectionFactory(boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : ioService(ioService), eventLoop(eventLoop) {
}
boost::shared_ptr<Connection> BoostConnectionFactory::createConnection() {
diff --git a/Swiften/Network/BoostConnectionFactory.h b/Swiften/Network/BoostConnectionFactory.h
index 551defe..ea9d656 100644
--- a/Swiften/Network/BoostConnectionFactory.h
+++ b/Swiften/Network/BoostConnectionFactory.h
@@ -16,12 +16,12 @@ namespace Swift {
class BoostConnectionFactory : public ConnectionFactory {
public:
- BoostConnectionFactory(boost::asio::io_service*, EventLoop* eventLoop);
+ BoostConnectionFactory(boost::shared_ptr<boost::asio::io_service>, EventLoop* eventLoop);
virtual boost::shared_ptr<Connection> createConnection();
private:
- boost::asio::io_service* ioService;
+ boost::shared_ptr<boost::asio::io_service> ioService;
EventLoop* eventLoop;
};
}
diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp
index 839c990..4c6403c 100644
--- a/Swiften/Network/BoostConnectionServer.cpp
+++ b/Swiften/Network/BoostConnectionServer.cpp
@@ -13,7 +13,7 @@
namespace Swift {
-BoostConnectionServer::BoostConnectionServer(int port, boost::asio::io_service* ioService, EventLoop* eventLoop) : port_(port), ioService_(ioService), eventLoop(eventLoop), acceptor_(NULL) {
+BoostConnectionServer::BoostConnectionServer(int port, boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : port_(port), ioService_(ioService), eventLoop(eventLoop), acceptor_(NULL) {
}
@@ -50,7 +50,7 @@ void BoostConnectionServer::stop(boost::optional<Error> e) {
}
void BoostConnectionServer::acceptNextConnection() {
- BoostConnection::ref newConnection(BoostConnection::create(&acceptor_->io_service(), eventLoop));
+ BoostConnection::ref newConnection(BoostConnection::create(ioService_, eventLoop));
acceptor_->async_accept(newConnection->getSocket(),
boost::bind(&BoostConnectionServer::handleAccept, shared_from_this(), newConnection, boost::asio::placeholders::error));
}
diff --git a/Swiften/Network/BoostConnectionServer.h b/Swiften/Network/BoostConnectionServer.h
index 223f264..a45e598 100644
--- a/Swiften/Network/BoostConnectionServer.h
+++ b/Swiften/Network/BoostConnectionServer.h
@@ -25,7 +25,7 @@ namespace Swift {
UnknownError
};
- static ref create(int port, boost::asio::io_service* ioService, EventLoop* eventLoop) {
+ static ref create(int port, boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) {
return ref(new BoostConnectionServer(port, ioService, eventLoop));
}
@@ -37,7 +37,7 @@ namespace Swift {
boost::signal<void (boost::optional<Error>)> onStopped;
private:
- BoostConnectionServer(int port, boost::asio::io_service* ioService, EventLoop* eventLoop);
+ BoostConnectionServer(int port, boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop);
void stop(boost::optional<Error> e);
void acceptNextConnection();
@@ -45,7 +45,7 @@ namespace Swift {
private:
int port_;
- boost::asio::io_service* ioService_;
+ boost::shared_ptr<boost::asio::io_service> ioService_;
EventLoop* eventLoop;
boost::asio::ip::tcp::acceptor* acceptor_;
};
diff --git a/Swiften/Network/BoostIOServiceThread.cpp b/Swiften/Network/BoostIOServiceThread.cpp
index 50fe9a8..031e7b5 100644
--- a/Swiften/Network/BoostIOServiceThread.cpp
+++ b/Swiften/Network/BoostIOServiceThread.cpp
@@ -6,19 +6,24 @@
#include "Swiften/Network/BoostIOServiceThread.h"
+#include <boost/smart_ptr/make_shared.hpp>
+
namespace Swift {
-BoostIOServiceThread::BoostIOServiceThread() : thread_(boost::bind(&BoostIOServiceThread::doRun, this)) {
+BoostIOServiceThread::BoostIOServiceThread() {
+ ioService_ = boost::make_shared<boost::asio::io_service>();
+ thread_ = new boost::thread(boost::bind(&BoostIOServiceThread::doRun, this));
}
BoostIOServiceThread::~BoostIOServiceThread() {
- ioService_.stop();
- thread_.join();
+ ioService_->stop();
+ thread_->join();
+ delete thread_;
}
void BoostIOServiceThread::doRun() {
- boost::asio::io_service::work work(ioService_);
- ioService_.run();
+ boost::asio::io_service::work work(*ioService_);
+ ioService_->run();
}
}
diff --git a/Swiften/Network/BoostIOServiceThread.h b/Swiften/Network/BoostIOServiceThread.h
index 3cbea28..1f72049 100644
--- a/Swiften/Network/BoostIOServiceThread.h
+++ b/Swiften/Network/BoostIOServiceThread.h
@@ -8,6 +8,7 @@
#include <boost/asio.hpp>
#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
namespace Swift {
class BoostIOServiceThread {
@@ -15,7 +16,7 @@ namespace Swift {
BoostIOServiceThread();
~BoostIOServiceThread();
- boost::asio::io_service& getIOService() {
+ boost::shared_ptr<boost::asio::io_service> getIOService() {
return ioService_;
}
@@ -23,7 +24,7 @@ namespace Swift {
void doRun();
private:
- boost::asio::io_service ioService_;
- boost::thread thread_;
+ boost::shared_ptr<boost::asio::io_service> ioService_;
+ boost::thread* thread_;
};
}
diff --git a/Swiften/Network/BoostNetworkFactories.cpp b/Swiften/Network/BoostNetworkFactories.cpp
index b9d5b49..a8e3d0a 100644
--- a/Swiften/Network/BoostNetworkFactories.cpp
+++ b/Swiften/Network/BoostNetworkFactories.cpp
@@ -12,8 +12,8 @@
namespace Swift {
BoostNetworkFactories::BoostNetworkFactories(EventLoop* eventLoop) {
- timerFactory = new BoostTimerFactory(&ioServiceThread.getIOService(), eventLoop);
- connectionFactory = new BoostConnectionFactory(&ioServiceThread.getIOService(), eventLoop);
+ timerFactory = new BoostTimerFactory(ioServiceThread.getIOService(), eventLoop);
+ connectionFactory = new BoostConnectionFactory(ioServiceThread.getIOService(), eventLoop);
domainNameResolver = new PlatformDomainNameResolver(eventLoop);
}
diff --git a/Swiften/Network/BoostTimer.cpp b/Swiften/Network/BoostTimer.cpp
index 1812688..12d06c1 100644
--- a/Swiften/Network/BoostTimer.cpp
+++ b/Swiften/Network/BoostTimer.cpp
@@ -13,8 +13,8 @@
namespace Swift {
-BoostTimer::BoostTimer(int milliseconds, boost::asio::io_service* service, EventLoop* eventLoop) :
- timeout(milliseconds), timer(*service), eventLoop(eventLoop) {
+BoostTimer::BoostTimer(int milliseconds, boost::shared_ptr<boost::asio::io_service> service, EventLoop* eventLoop) :
+ timeout(milliseconds), ioService(service), timer(*service), eventLoop(eventLoop) {
}
void BoostTimer::start() {
diff --git a/Swiften/Network/BoostTimer.h b/Swiften/Network/BoostTimer.h
index 548133f..1139dcf 100644
--- a/Swiften/Network/BoostTimer.h
+++ b/Swiften/Network/BoostTimer.h
@@ -20,7 +20,7 @@ namespace Swift {
public:
typedef boost::shared_ptr<BoostTimer> ref;
- static ref create(int milliseconds, boost::asio::io_service* service, EventLoop* eventLoop) {
+ static ref create(int milliseconds, boost::shared_ptr<boost::asio::io_service> service, EventLoop* eventLoop) {
return ref(new BoostTimer(milliseconds, service, eventLoop));
}
@@ -28,12 +28,13 @@ namespace Swift {
virtual void stop();
private:
- BoostTimer(int milliseconds, boost::asio::io_service* service, EventLoop* eventLoop);
+ BoostTimer(int milliseconds, boost::shared_ptr<boost::asio::io_service> service, EventLoop* eventLoop);
void handleTimerTick(const boost::system::error_code& error);
private:
int timeout;
+ boost::shared_ptr<boost::asio::io_service> ioService;
boost::asio::deadline_timer timer;
EventLoop* eventLoop;
};
diff --git a/Swiften/Network/BoostTimerFactory.cpp b/Swiften/Network/BoostTimerFactory.cpp
index 38842f9..b8e628f 100644
--- a/Swiften/Network/BoostTimerFactory.cpp
+++ b/Swiften/Network/BoostTimerFactory.cpp
@@ -9,7 +9,7 @@
namespace Swift {
-BoostTimerFactory::BoostTimerFactory(boost::asio::io_service* ioService, EventLoop* eventLoop) : ioService(ioService), eventLoop(eventLoop) {
+BoostTimerFactory::BoostTimerFactory(boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : ioService(ioService), eventLoop(eventLoop) {
}
boost::shared_ptr<Timer> BoostTimerFactory::createTimer(int milliseconds) {
diff --git a/Swiften/Network/BoostTimerFactory.h b/Swiften/Network/BoostTimerFactory.h
index a987763..c0e9ef7 100644
--- a/Swiften/Network/BoostTimerFactory.h
+++ b/Swiften/Network/BoostTimerFactory.h
@@ -17,12 +17,12 @@ namespace Swift {
class BoostTimerFactory : public TimerFactory {
public:
- BoostTimerFactory(boost::asio::io_service*, EventLoop* eventLoop);
+ BoostTimerFactory(boost::shared_ptr<boost::asio::io_service>, EventLoop* eventLoop);
virtual boost::shared_ptr<Timer> createTimer(int milliseconds);
private:
- boost::asio::io_service* ioService;
+ boost::shared_ptr<boost::asio::io_service> ioService;
EventLoop* eventLoop;
};
}