diff options
-rw-r--r-- | Swiften/Client/ClientSessionStanzaChannel.cpp | 15 | ||||
-rw-r--r-- | Swiften/Client/ClientSessionStanzaChannel.h | 4 | ||||
-rw-r--r-- | Swiften/Network/ChainedConnector.cpp | 15 | ||||
-rw-r--r-- | Swiften/Network/ChainedConnector.h | 10 |
4 files changed, 34 insertions, 10 deletions
diff --git a/Swiften/Client/ClientSessionStanzaChannel.cpp b/Swiften/Client/ClientSessionStanzaChannel.cpp index 3d7b9f7..3dc8c59 100644 --- a/Swiften/Client/ClientSessionStanzaChannel.cpp +++ b/Swiften/Client/ClientSessionStanzaChannel.cpp @@ -1,19 +1,30 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Client/ClientSessionStanzaChannel.h> -#include <boost/bind.hpp> #include <iostream> +#include <boost/bind.hpp> + namespace Swift { +ClientSessionStanzaChannel::~ClientSessionStanzaChannel() { + if (session) { + session->onFinished.disconnect(boost::bind(&ClientSessionStanzaChannel::handleSessionFinished, this, _1)); + session->onStanzaReceived.disconnect(boost::bind(&ClientSessionStanzaChannel::handleStanza, this, _1)); + session->onStanzaAcked.disconnect(boost::bind(&ClientSessionStanzaChannel::handleStanzaAcked, this, _1)); + session->onInitialized.disconnect(boost::bind(&ClientSessionStanzaChannel::handleSessionInitialized, this)); + session.reset(); + } +} + void ClientSessionStanzaChannel::setSession(boost::shared_ptr<ClientSession> session) { assert(!this->session); this->session = session; session->onInitialized.connect(boost::bind(&ClientSessionStanzaChannel::handleSessionInitialized, this)); session->onFinished.connect(boost::bind(&ClientSessionStanzaChannel::handleSessionFinished, this, _1)); session->onStanzaReceived.connect(boost::bind(&ClientSessionStanzaChannel::handleStanza, this, _1)); diff --git a/Swiften/Client/ClientSessionStanzaChannel.h b/Swiften/Client/ClientSessionStanzaChannel.h index 1104416..0ffcd9d 100644 --- a/Swiften/Client/ClientSessionStanzaChannel.h +++ b/Swiften/Client/ClientSessionStanzaChannel.h @@ -9,22 +9,24 @@ #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Base/IDGenerator.h> #include <Swiften/Client/ClientSession.h> #include <Swiften/Client/StanzaChannel.h> -#include <Swiften/Elements/Message.h> #include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/Message.h> #include <Swiften/Elements/Presence.h> namespace Swift { /** * StanzaChannel implementation around a ClientSession. */ class SWIFTEN_API ClientSessionStanzaChannel : public StanzaChannel { public: + virtual ~ClientSessionStanzaChannel(); + void setSession(boost::shared_ptr<ClientSession> session); void sendIQ(boost::shared_ptr<IQ> iq); void sendMessage(boost::shared_ptr<Message> message); void sendPresence(boost::shared_ptr<Presence> presence); bool getStreamManagementEnabled() const; diff --git a/Swiften/Network/ChainedConnector.cpp b/Swiften/Network/ChainedConnector.cpp index ac48d20..3cc4057 100644 --- a/Swiften/Network/ChainedConnector.cpp +++ b/Swiften/Network/ChainedConnector.cpp @@ -1,21 +1,22 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/ChainedConnector.h> -#include <boost/bind.hpp> #include <typeinfo> +#include <boost/bind.hpp> + #include <Swiften/Base/Log.h> #include <Swiften/Base/foreach.h> -#include <Swiften/Network/Connector.h> #include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/Connector.h> using namespace Swift; ChainedConnector::ChainedConnector( const std::string& hostname, int port, @@ -29,12 +30,20 @@ ChainedConnector::ChainedConnector( resolver(resolver), connectionFactories(connectionFactories), timerFactory(timerFactory), timeoutMilliseconds(0) { } +ChainedConnector::~ChainedConnector() { + if (currentConnector) { + currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2)); + currentConnector->stop(); + currentConnector.reset(); + } +} + void ChainedConnector::setTimeoutMilliseconds(int milliseconds) { timeoutMilliseconds = milliseconds; } void ChainedConnector::start() { SWIFT_LOG(debug) << "Starting queued connector for " << hostname << std::endl; diff --git a/Swiften/Network/ChainedConnector.h b/Swiften/Network/ChainedConnector.h index 77fa6fd..9bcc961 100644 --- a/Swiften/Network/ChainedConnector.h +++ b/Swiften/Network/ChainedConnector.h @@ -1,34 +1,36 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <deque> #include <string> #include <vector> -#include <deque> -#include <boost/shared_ptr.hpp> + #include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> -#include <Swiften/Base/boost_bsignals.h> #include <Swiften/Base/Error.h> +#include <Swiften/Base/boost_bsignals.h> namespace Swift { class Connection; class Connector; class ConnectionFactory; class TimerFactory; class DomainNameResolver; class SWIFTEN_API ChainedConnector { public: ChainedConnector(const std::string& hostname, int port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver*, const std::vector<ConnectionFactory*>&, TimerFactory*); + ~ChainedConnector(); void setTimeoutMilliseconds(int milliseconds); void start(); void stop(); boost::signal<void (boost::shared_ptr<Connection>, boost::shared_ptr<Error>)> onConnectFinished; |