summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Limber/main.cpp')
-rw-r--r--Limber/main.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/Limber/main.cpp b/Limber/main.cpp
index 200f2e4..5d1bb6a 100644
--- a/Limber/main.cpp
+++ b/Limber/main.cpp
@@ -3,6 +3,7 @@
#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"
@@ -12,6 +13,7 @@
#include "Swiften/Base/IDGenerator.h"
#include "Swiften/EventLoop/MainEventLoop.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
+#include "Swiften/EventLoop/EventOwner.h"
#include "Swiften/Elements/Stanza.h"
#include "Swiften/Network/ConnectionServer.h"
#include "Swiften/Network/BoostConnection.h"
@@ -22,9 +24,12 @@
using namespace Swift;
-class BoostConnectionServer : public ConnectionServer {
+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();
}
@@ -32,12 +37,12 @@ class BoostConnectionServer : public ConnectionServer {
void acceptNextConnection() {
boost::shared_ptr<BoostConnection> newConnection(new BoostConnection(&acceptor_.io_service()));
acceptor_.async_accept(newConnection->getSocket(),
- boost::bind(&BoostConnectionServer::handleAccept, this, newConnection, boost::asio::placeholders::error));
+ 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), this);
+ MainEventLoop::postEvent(boost::bind(boost::ref(onNewConnection), newConnection), shared_from_this());
newConnection->listen();
acceptNextConnection();
}
@@ -49,12 +54,9 @@ class BoostConnectionServer : public ConnectionServer {
class Server {
public:
Server(UserRegistry* userRegistry) : userRegistry_(userRegistry) {
- serverFromClientConnectionServer_ = new BoostConnectionServer(5222, boostIOServiceThread_.getIOService());
+ serverFromClientConnectionServer_ = boost::shared_ptr<BoostConnectionServer>(new BoostConnectionServer(5224, boostIOServiceThread_.getIOService()));
serverFromClientConnectionServer_->onNewConnection.connect(boost::bind(&Server::handleNewConnection, this, _1));
- }
-
- ~Server() {
- delete serverFromClientConnectionServer_;
+ serverFromClientConnectionServer_->start();
}
private:
@@ -101,7 +103,7 @@ class Server {
IDGenerator idGenerator_;
UserRegistry* userRegistry_;
BoostIOServiceThread boostIOServiceThread_;
- BoostConnectionServer* serverFromClientConnectionServer_;
+ boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer_;
std::vector<ServerFromClientSession*> serverFromClientSessions_;
FullPayloadParserFactoryCollection payloadParserFactories_;
FullPayloadSerializerCollection payloadSerializers_;
@@ -110,7 +112,10 @@ class Server {
int main() {
SimpleEventLoop eventLoop;
SimpleUserRegistry userRegistry;
- userRegistry.addUser(JID("remko@limber"), "pass");
+ userRegistry.addUser(JID("remko@localhost"), "remko");
+ userRegistry.addUser(JID("kevin@localhost"), "kevin");
+ userRegistry.addUser(JID("remko@limber.swift.im"), "remko");
+ userRegistry.addUser(JID("kevin@limber.swift.im"), "kevin");
Server server(&userRegistry);
eventLoop.run();
return 0;