diff options
Diffstat (limited to 'Swiften/Client/Session.cpp')
-rw-r--r-- | Swiften/Client/Session.cpp | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/Swiften/Client/Session.cpp b/Swiften/Client/Session.cpp index 6c2a873..1bd2b22 100644 --- a/Swiften/Client/Session.cpp +++ b/Swiften/Client/Session.cpp @@ -24,16 +24,21 @@ namespace Swift { -Session::Session(const JID& jid, ConnectionFactory* connectionFactory, TLSLayerFactory* tlsLayerFactory, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers) : - jid_(jid), - connectionFactory_(connectionFactory), - tlsLayerFactory_(tlsLayerFactory), - payloadParserFactories_(payloadParserFactories), - payloadSerializers_(payloadSerializers), - state_(Initial), - error_(NoError), - streamStack_(0), - needSessionStart_(false) { +Session::Session( + const JID& jid, + boost::shared_ptr<Connection> connection, + TLSLayerFactory* tlsLayerFactory, + PayloadParserFactoryCollection* payloadParserFactories, + PayloadSerializerCollection* payloadSerializers) : + jid_(jid), + tlsLayerFactory_(tlsLayerFactory), + payloadParserFactories_(payloadParserFactories), + payloadSerializers_(payloadSerializers), + state_(Initial), + error_(NoError), + connection_(connection), + streamStack_(0), + needSessionStart_(false) { } Session::~Session() { @@ -42,11 +47,11 @@ Session::~Session() { void Session::start() { assert(state_ == Initial); - state_ = Connecting; - connection_ = connectionFactory_->createConnection(); - connection_->onConnected.connect(boost::bind(&Session::handleConnected, this)); + connection_->onDisconnected.connect(boost::bind(&Session::handleDisconnected, this, _1)); - connection_->connect(jid_.getDomain()); + initializeStreamStack(); + state_ = WaitingForStreamStart; + sendStreamHeader(); } void Session::stop() { @@ -54,13 +59,6 @@ void Session::stop() { connection_->disconnect(); } -void Session::handleConnected() { - assert(state_ == Connecting); - initializeStreamStack(); - state_ = WaitingForStreamStart; - sendStreamHeader(); -} - void Session::sendStreamHeader() { ProtocolHeader header; header.setTo(jid_.getDomain()); @@ -81,18 +79,12 @@ void Session::initializeStreamStack() { void Session::handleDisconnected(const boost::optional<Connection::Error>& error) { if (error) { switch (*error) { - case Connection::DomainNameResolveError: - setError(DomainNameResolveError); - break; case Connection::ReadError: setError(ConnectionReadError); break; case Connection::WriteError: setError(ConnectionWriteError); break; - case Connection::ConnectionError: - setError(ConnectionError); - break; } } } |