summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-01-22 14:00:01 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-01-22 14:00:01 (GMT)
commitdf029015f47f284ced01b8d1f11c4d48cc2f2564 (patch)
tree455d47a7fcb0d9d90bef6a6c63bdc7120eaec286 /Swiften/Client/ClientSession.cpp
parent940cb5e744564ec15b805a9e5388e1fa5c60d703 (diff)
downloadswift-df029015f47f284ced01b8d1f11c4d48cc2f2564.zip
swift-df029015f47f284ced01b8d1f11c4d48cc2f2564.tar.bz2
Close connection properly before quitting.
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()));