Call finishSession in User destructor in server mode

This commit is contained in:
HanzZ 2011-07-20 02:16:58 +02:00
parent fcb17bc571
commit e31c077947
7 changed files with 51 additions and 4 deletions

View file

@ -141,6 +141,7 @@ void Server::handleSessionFinished(boost::shared_ptr<ServerFromClientSession> se
dynamic_cast<ServerStanzaChannel *>(stanzaChannel_)->onPresenceReceived(presence);
}
serverFromClientSessions.erase(std::remove(serverFromClientSessions.begin(), serverFromClientSessions.end(), session), serverFromClientSessions.end());
std::cout << "FINISH SESSION2 " << serverFromClientSessions.size() << "\n";
session->onSessionStarted.disconnect(
boost::bind(&Server::handleSessionStarted, this, session));
session->onSessionFinished.disconnect(

View file

@ -48,6 +48,8 @@ ServerFromClientSession::ServerFromClientSession(
ServerFromClientSession::~ServerFromClientSession() {
std::cout << "DESTRUCTOR;\n";
userRegistry_->onPasswordValid.disconnect(boost::bind(&ServerFromClientSession::handlePasswordValid, this, _1));
userRegistry_->onPasswordInvalid.disconnect(boost::bind(&ServerFromClientSession::handlePasswordInvalid, this, _1));
if (tlsLayer) {
delete tlsLayer;
}

View file

@ -6,6 +6,7 @@
#include "Swiften/Server/ServerStanzaChannel.h"
#include "Swiften/Base/Error.h"
#include <iostream>
#include <boost/bind.hpp>
@ -55,13 +56,17 @@ void ServerStanzaChannel::sendPresence(boost::shared_ptr<Presence> presence) {
void ServerStanzaChannel::finishSession(const JID& to, boost::shared_ptr<Element> element) {
std::vector<boost::shared_ptr<ServerFromClientSession> > candidateSessions;
for (std::list<boost::shared_ptr<ServerFromClientSession> >::const_iterator i = sessions[to.toBare().toString()].begin(); i != sessions[to.toBare().toString()].end(); ++i) {
(*i)->sendElement(element);
if (element) {
(*i)->sendElement(element);
}
candidateSessions.push_back(*i);
}
for (std::vector<boost::shared_ptr<ServerFromClientSession> >::const_iterator i = candidateSessions.begin(); i != candidateSessions.end(); ++i) {
(*i)->finishSession();
sessions[to.toBare().toString()].remove(*i);
std::cout << "FINISH SESSION " << sessions[to.toBare().toString()].size() << "\n";
}
}

View file

@ -7,13 +7,34 @@
#include "transport/networkpluginserver.h"
#include "transport/admininterface.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
#include "sys/signal.h"
using namespace Transport;
Swift::SimpleEventLoop *eventLoop_ = NULL;
static void spectrum_sigint_handler(int sig) {
eventLoop_->stop();
}
static void spectrum_sigterm_handler(int sig) {
eventLoop_->stop();
}
int main(int argc, char **argv)
{
Config config;
if (signal(SIGINT, spectrum_sigint_handler) == SIG_ERR) {
std::cout << "SIGINT handler can't be set\n";
return -1;
}
if (signal(SIGTERM, spectrum_sigterm_handler) == SIG_ERR) {
std::cout << "SIGTERM handler can't be set\n";
return -1;
}
boost::program_options::options_description desc("Usage: spectrum [OPTIONS] <config_file.cfg>\nAllowed options");
desc.add_options()
("help,h", "help")
@ -69,8 +90,9 @@ int main(int argc, char **argv)
}
UserManager userManager(&transport, &userRegistry, storageBackend);
UserRegistration *userRegistration = NULL;
if (storageBackend) {
UserRegistration *userRegistration = new UserRegistration(&transport, &userManager, storageBackend);
userRegistration = new UserRegistration(&transport, &userManager, storageBackend);
userRegistration->start();
// logger.setUserRegistration(&userRegistration);
}
@ -80,5 +102,12 @@ int main(int argc, char **argv)
AdminInterface adminInterface(&transport, &userManager, &plugin, storageBackend);
eventLoop_ = &eventLoop;
eventLoop.run();
if (userRegistration) {
userRegistration->stop();
delete userRegistration;
}
delete storageBackend;
}

View file

@ -168,6 +168,9 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
NetworkPluginServer::~NetworkPluginServer() {
m_pingTimer->stop();
m_server->stop();
m_server.reset();
delete m_component->m_factory;
delete m_vcardResponder;
delete m_rosterResponder;
}

View file

@ -134,10 +134,13 @@ Component::~Component() {
delete m_capsManager;
delete m_capsMemoryStorage;
delete m_discoInfoResponder;
delete m_discoItemsResponder;
if (m_component)
delete m_component;
if (m_server)
if (m_server) {
m_server->stop();
delete m_server;
}
delete m_factories;
}

View file

@ -62,6 +62,10 @@ User::User(const Swift::JID &jid, UserInfo &userInfo, Component *component, User
User::~User(){
LOG4CXX_INFO(logger, m_jid.toString() << ": Destroying");
if (m_component->inServerMode()) {
dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::Element>());
}
m_reconnectTimer->stop();
delete m_rosterManager;
delete m_conversationManager;
@ -194,7 +198,7 @@ void User::handleDisconnected(const std::string &error) {
// Remove user later just to be sure there won't be double-free.
// We can't be sure finishSession sends unavailable presence everytime, so check if user gets removed
// in finishSession(...) call and if not, remove it here.
std::string jid = m_jid.toBare().toString();
std::string jid = m_jid.toBare().toString();
dynamic_cast<Swift::ServerStanzaChannel *>(m_component->getStanzaChannel())->finishSession(m_jid, boost::shared_ptr<Swift::Element>(new Swift::StreamError()));
if (m_userManager->getUser(jid) != NULL) {
m_userManager->removeUser(this);