summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/BoostIOServiceThread.cpp18
-rw-r--r--Swiften/Network/BoostIOServiceThread.h23
-rw-r--r--Swiften/Network/Makefile.inc1
3 files changed, 42 insertions, 0 deletions
diff --git a/Swiften/Network/BoostIOServiceThread.cpp b/Swiften/Network/BoostIOServiceThread.cpp
new file mode 100644
index 0000000..01c3bf3
--- /dev/null
+++ b/Swiften/Network/BoostIOServiceThread.cpp
@@ -0,0 +1,18 @@
+#include "Swiften/Network/BoostIOServiceThread.h"
+
+namespace Swift {
+
+BoostIOServiceThread::BoostIOServiceThread() : thread_(boost::bind(&BoostIOServiceThread::doRun, this)) {
+}
+
+BoostIOServiceThread::~BoostIOServiceThread() {
+ ioService_.stop();
+ thread_.join();
+}
+
+void BoostIOServiceThread::doRun() {
+ boost::asio::io_service::work work(ioService_);
+ ioService_.run();
+}
+
+}
diff --git a/Swiften/Network/BoostIOServiceThread.h b/Swiften/Network/BoostIOServiceThread.h
new file mode 100644
index 0000000..ddc90bf
--- /dev/null
+++ b/Swiften/Network/BoostIOServiceThread.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <boost/asio.hpp>
+#include <boost/thread.hpp>
+
+namespace Swift {
+ class BoostIOServiceThread {
+ public:
+ BoostIOServiceThread();
+ ~BoostIOServiceThread();
+
+ boost::asio::io_service& getIOService() {
+ return ioService_;
+ }
+
+ private:
+ void doRun();
+
+ private:
+ boost::asio::io_service ioService_;
+ boost::thread thread_;
+ };
+}
diff --git a/Swiften/Network/Makefile.inc b/Swiften/Network/Makefile.inc
index b0f0fd1..3e4ece6 100644
--- a/Swiften/Network/Makefile.inc
+++ b/Swiften/Network/Makefile.inc
@@ -6,6 +6,7 @@ SWIFTEN_SOURCES += \
Swiften/Network/BoostConnectionFactory.cpp \
Swiften/Network/ConnectionServer.cpp \
Swiften/Network/IncomingConnection.cpp \
+ Swiften/Network/BoostIOServiceThread.cpp \
Swiften/Network/Timer.cpp
include Swiften/Network/UnitTest/Makefile.inc