summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-16 16:45:48 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-16 16:45:48 (GMT)
commit3adeaee96ab80cc6552798ad3f5812e934b45677 (patch)
treee79728d2cb671d40c6d2dea0b0260b89cb62febf
parent14f7f9f37702635019c46d97f57ee6de8c5c749e (diff)
downloadswift-contrib-3adeaee96ab80cc6552798ad3f5812e934b45677.zip
swift-contrib-3adeaee96ab80cc6552798ad3f5812e934b45677.tar.bz2
Moved BoostConnectionServer to Swiften.
-rw-r--r--Limber/main.cpp34
-rw-r--r--Swiften/Network/BoostConnectionServer.cpp31
-rw-r--r--Swiften/Network/BoostConnectionServer.h25
-rw-r--r--Swiften/Network/Makefile.inc1
-rw-r--r--Swiften/Network/Timer.cpp6
5 files changed, 62 insertions, 35 deletions
diff --git a/Limber/main.cpp b/Limber/main.cpp
index 5d1bb6a..c478924 100644
--- a/Limber/main.cpp
+++ b/Limber/main.cpp
@@ -1,15 +1,11 @@
-#include <iostream>
#include <string>
-#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
#include "Swiften/Elements/IQ.h"
#include "Swiften/Elements/RosterPayload.h"
#include "Swiften/Elements/VCard.h"
#include "Swiften/Server/SimpleUserRegistry.h"
-#include "Swiften/Base/ByteArray.h"
#include "Swiften/Base/IDGenerator.h"
#include "Swiften/EventLoop/MainEventLoop.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
@@ -18,43 +14,17 @@
#include "Swiften/Network/ConnectionServer.h"
#include "Swiften/Network/BoostConnection.h"
#include "Swiften/Network/BoostIOServiceThread.h"
+#include "Swiften/Network/BoostConnectionServer.h"
#include "Swiften/Server/ServerFromClientSession.h"
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h"
using namespace Swift;
-class BoostConnectionServer : public ConnectionServer, public EventOwner, public boost::enable_shared_from_this<BoostConnectionServer> {
- public:
- BoostConnectionServer(int port, boost::asio::io_service& ioService) : acceptor_(ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)) {
- }
-
- void start() {
- acceptNextConnection();
- }
-
- private:
- void acceptNextConnection() {
- boost::shared_ptr<BoostConnection> newConnection(new BoostConnection(&acceptor_.io_service()));
- acceptor_.async_accept(newConnection->getSocket(),
- boost::bind(&BoostConnectionServer::handleAccept, shared_from_this(), newConnection, boost::asio::placeholders::error));
- }
-
- void handleAccept(boost::shared_ptr<BoostConnection> newConnection, const boost::system::error_code& error) {
- if (!error) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onNewConnection), newConnection), shared_from_this());
- newConnection->listen();
- acceptNextConnection();
- }
- }
-
- boost::asio::ip::tcp::acceptor acceptor_;
-};
-
class Server {
public:
Server(UserRegistry* userRegistry) : userRegistry_(userRegistry) {
- serverFromClientConnectionServer_ = boost::shared_ptr<BoostConnectionServer>(new BoostConnectionServer(5224, boostIOServiceThread_.getIOService()));
+ serverFromClientConnectionServer_ = boost::shared_ptr<BoostConnectionServer>(new BoostConnectionServer(5224, &boostIOServiceThread_.getIOService()));
serverFromClientConnectionServer_->onNewConnection.connect(boost::bind(&Server::handleNewConnection, this, _1));
serverFromClientConnectionServer_->start();
}
diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp
new file mode 100644
index 0000000..18a3ca4
--- /dev/null
+++ b/Swiften/Network/BoostConnectionServer.cpp
@@ -0,0 +1,31 @@
+#include "Swiften/Network/BoostConnectionServer.h"
+
+#include <boost/bind.hpp>
+
+#include "Swiften/EventLoop/MainEventLoop.h"
+
+namespace Swift {
+
+BoostConnectionServer::BoostConnectionServer(int port, boost::asio::io_service* ioService) : acceptor_(*ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)) {
+}
+
+
+void BoostConnectionServer::start() {
+ acceptNextConnection();
+}
+
+void BoostConnectionServer::acceptNextConnection() {
+ boost::shared_ptr<BoostConnection> newConnection(new BoostConnection(&acceptor_.io_service()));
+ acceptor_.async_accept(newConnection->getSocket(),
+ boost::bind(&BoostConnectionServer::handleAccept, shared_from_this(), newConnection, boost::asio::placeholders::error));
+}
+
+void BoostConnectionServer::handleAccept(boost::shared_ptr<BoostConnection> newConnection, const boost::system::error_code& error) {
+ if (!error) {
+ MainEventLoop::postEvent(boost::bind(boost::ref(onNewConnection), newConnection), shared_from_this());
+ newConnection->listen();
+ acceptNextConnection();
+ }
+}
+
+}
diff --git a/Swiften/Network/BoostConnectionServer.h b/Swiften/Network/BoostConnectionServer.h
new file mode 100644
index 0000000..c92318e
--- /dev/null
+++ b/Swiften/Network/BoostConnectionServer.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
+#include <boost/asio.hpp>
+
+#include "Swiften/Network/BoostConnection.h"
+#include "Swiften/Network/ConnectionServer.h"
+#include "Swiften/EventLoop/EventOwner.h"
+
+namespace Swift {
+ class BoostConnectionServer : public ConnectionServer, public EventOwner, public boost::enable_shared_from_this<BoostConnectionServer> {
+ public:
+ BoostConnectionServer(int port, boost::asio::io_service* ioService);
+
+ void start();
+
+ private:
+ void acceptNextConnection();
+ void handleAccept(boost::shared_ptr<BoostConnection> newConnection, const boost::system::error_code& error);
+
+ private:
+ boost::asio::ip::tcp::acceptor acceptor_;
+ };
+}
diff --git a/Swiften/Network/Makefile.inc b/Swiften/Network/Makefile.inc
index d8c1ee9..94a8727 100644
--- a/Swiften/Network/Makefile.inc
+++ b/Swiften/Network/Makefile.inc
@@ -4,6 +4,7 @@ SWIFTEN_SOURCES += \
Swiften/Network/ConnectionFactory.cpp \
Swiften/Network/BoostConnection.cpp \
Swiften/Network/BoostConnectionFactory.cpp \
+ Swiften/Network/BoostConnectionServer.cpp \
Swiften/Network/ConnectionServer.cpp \
Swiften/Network/BoostIOServiceThread.cpp \
Swiften/Network/Timer.cpp
diff --git a/Swiften/Network/Timer.cpp b/Swiften/Network/Timer.cpp
index 8999113..f3b296c 100644
--- a/Swiften/Network/Timer.cpp
+++ b/Swiften/Network/Timer.cpp
@@ -8,13 +8,13 @@ namespace Swift {
Timer::Timer(int milliseconds) :
timeout_(milliseconds), ioService_(0), thread_(0), timer_(0) {
- ioService_ = new boost::asio::io_service();
+ ioService_ = new boost::asio::io_service();
}
Timer::~Timer() {
//MainEventLoop::removeEventsFromOwner(shared_from_this());
- ioService_->stop();
- thread_->join();
+ ioService_->stop();
+ thread_->join();
delete timer_;
delete thread_;
delete ioService_;