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 /Limber/main.cpp
parent14f7f9f37702635019c46d97f57ee6de8c5c749e (diff)
downloadswift-3adeaee96ab80cc6552798ad3f5812e934b45677.zip
swift-3adeaee96ab80cc6552798ad3f5812e934b45677.tar.bz2
Moved BoostConnectionServer to Swiften.
Diffstat (limited to 'Limber/main.cpp')
-rw-r--r--Limber/main.cpp34
1 files changed, 2 insertions, 32 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();
}