summaryrefslogtreecommitdiffstats
path: root/Nim
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-17 19:15:54 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-17 19:15:54 (GMT)
commita328466bc492c50c443e406b9325542a75182327 (patch)
tree8388cb92845a20d5c495e5940f5f16a6b95363a3 /Nim
parent436ae921afbc5c2b461ee9b2d8fa9b1c869ed274 (diff)
downloadswift-contrib-a328466bc492c50c443e406b9325542a75182327.zip
swift-contrib-a328466bc492c50c443e406b9325542a75182327.tar.bz2
Implemented clean session/connection shutdown.
Diffstat (limited to 'Nim')
-rw-r--r--Nim/main.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/Nim/main.cpp b/Nim/main.cpp
index 6747d4a..7c7105e 100644
--- a/Nim/main.cpp
+++ b/Nim/main.cpp
@@ -53,14 +53,15 @@ class Server {
private:
void handleNewConnection(boost::shared_ptr<Connection> c) {
- ServerFromClientSession* session = new ServerFromClientSession(idGenerator_.generateID(), c, &payloadParserFactories_, &payloadSerializers_, &userRegistry_);
+ boost::shared_ptr<ServerFromClientSession> session(new ServerFromClientSession(idGenerator_.generateID(), c, &payloadParserFactories_, &payloadSerializers_, &userRegistry_));
serverFromClientSessions_.push_back(session);
session->onStanzaReceived.connect(boost::bind(&Server::handleStanzaReceived, this, _1, session));
session->onSessionStarted.connect(boost::bind(&Server::handleSessionStarted, this, session));
session->onSessionFinished.connect(boost::bind(&Server::handleSessionFinished, this, session));
+ session->start();
}
- void handleSessionStarted(ServerFromClientSession* session) {
+ void handleSessionStarted(boost::shared_ptr<ServerFromClientSession> session) {
if (!dnsSDServiceRegistered_) {
dnsSDServiceRegistered_ = true;
dnsSDService_->onServiceRegistered.connect(boost::bind(&Server::handleServiceRegistered, this, _1));
@@ -81,16 +82,15 @@ class Server {
std::cout << "Service registered " << service.name << " " << service.type << " " << service.domain << std::endl;
}
- void handleSessionFinished(ServerFromClientSession* session) {
+ void handleSessionFinished(boost::shared_ptr<ServerFromClientSession> session) {
serverFromClientSessions_.erase(std::remove(serverFromClientSessions_.begin(), serverFromClientSessions_.end(), session), serverFromClientSessions_.end());
- delete session;
if (serverFromClientSessions_.empty()) {
dnsSDServiceRegistered_ = false;
dnsSDService_->unregisterService();
}
}
- void handleStanzaReceived(boost::shared_ptr<Stanza> stanza, ServerFromClientSession* session) {
+ void handleStanzaReceived(boost::shared_ptr<Stanza> stanza, boost::shared_ptr<ServerFromClientSession> session) {
stanza->setFrom(session->getJID());
if (!stanza->getTo().isValid()) {
stanza->setTo(JID(session->getDomain()));
@@ -124,7 +124,7 @@ class Server {
boost::shared_ptr<AppleDNSSDService> dnsSDService_;
boost::shared_ptr<LinkLocalRoster> linkLocalRoster_;
boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer_;
- std::vector<ServerFromClientSession*> serverFromClientSessions_;
+ std::vector< boost::shared_ptr<ServerFromClientSession> > serverFromClientSessions_;
FullPayloadParserFactoryCollection payloadParserFactories_;
FullPayloadSerializerCollection payloadSerializers_;
bool dnsSDServiceRegistered_;