summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Client/ClientSession.cpp')
-rw-r--r--Swiften/Client/ClientSession.cpp44
1 files changed, 26 insertions, 18 deletions
diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp
index 9400b56..9950a76 100644
--- a/Swiften/Client/ClientSession.cpp
+++ b/Swiften/Client/ClientSession.cpp
@@ -62,7 +62,7 @@ ClientSession::~ClientSession() {
void ClientSession::start() {
stream->onStreamStartReceived.connect(boost::bind(&ClientSession::handleStreamStart, shared_from_this(), _1));
stream->onElementReceived.connect(boost::bind(&ClientSession::handleElement, shared_from_this(), _1));
- stream->onClosed.connect(boost::bind(&ClientSession::handleStreamFinished, shared_from_this(), _1));
+ stream->onClosed.connect(boost::bind(&ClientSession::handleStreamClosed, shared_from_this(), _1));
stream->onTLSEncrypted.connect(boost::bind(&ClientSession::handleTLSEncrypted, shared_from_this()));
assert(state == Initial);
@@ -367,20 +367,10 @@ void ClientSession::continueAfterTLSEncrypted() {
sendStreamHeader();
}
-void ClientSession::handleStreamFinished(boost::shared_ptr<Swift::Error> error) {
- finishSession(error);
-}
-
-void ClientSession::finish() {
- finishSession(boost::shared_ptr<Error>());
-}
-
-void ClientSession::finishSession(Error::Type error) {
- finishSession(boost::shared_ptr<Swift::ClientSession::Error>(new Swift::ClientSession::Error(error)));
-}
-
-void ClientSession::finishSession(boost::shared_ptr<Swift::Error> error) {
+void ClientSession::handleStreamClosed(boost::shared_ptr<Swift::Error> streamError) {
+ State previousState = state;
state = Finished;
+
if (stanzaAckRequester_) {
stanzaAckRequester_->onRequestAck.disconnect(boost::bind(&ClientSession::requestAck, shared_from_this()));
stanzaAckRequester_->onStanzaAcked.disconnect(boost::bind(&ClientSession::handleStanzaAcked, shared_from_this(), _1));
@@ -393,14 +383,32 @@ void ClientSession::finishSession(boost::shared_ptr<Swift::Error> error) {
stream->setWhitespacePingEnabled(false);
stream->onStreamStartReceived.disconnect(boost::bind(&ClientSession::handleStreamStart, shared_from_this(), _1));
stream->onElementReceived.disconnect(boost::bind(&ClientSession::handleElement, shared_from_this(), _1));
- stream->onClosed.disconnect(boost::bind(&ClientSession::handleStreamFinished, shared_from_this(), _1));
+ stream->onClosed.disconnect(boost::bind(&ClientSession::handleStreamClosed, shared_from_this(), _1));
stream->onTLSEncrypted.disconnect(boost::bind(&ClientSession::handleTLSEncrypted, shared_from_this()));
- if (stream->isAvailable()) {
- stream->writeFooter();
+
+ if (previousState == Finishing) {
+ onFinished(error_);
}
- onFinished(error);
+ else {
+ onFinished(streamError);
+ }
+}
+
+void ClientSession::finish() {
+ finishSession(boost::shared_ptr<Error>());
}
+void ClientSession::finishSession(Error::Type error) {
+ finishSession(boost::shared_ptr<Swift::ClientSession::Error>(new Swift::ClientSession::Error(error)));
+}
+
+void ClientSession::finishSession(boost::shared_ptr<Swift::Error> error) {
+ state = Finishing;
+ error_ = error;
+ assert(stream->isOpen());
+ stream->writeFooter();
+ stream->close();
+}
void ClientSession::requestAck() {
stream->writeElement(boost::shared_ptr<StanzaAckRequest>(new StanzaAckRequest()));