diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-07-17 19:15:54 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-07-17 19:15:54 (GMT) |
commit | a328466bc492c50c443e406b9325542a75182327 (patch) | |
tree | 8388cb92845a20d5c495e5940f5f16a6b95363a3 /Swiften/Network | |
parent | 436ae921afbc5c2b461ee9b2d8fa9b1c869ed274 (diff) | |
download | swift-a328466bc492c50c443e406b9325542a75182327.zip swift-a328466bc492c50c443e406b9325542a75182327.tar.bz2 |
Implemented clean session/connection shutdown.
Diffstat (limited to 'Swiften/Network')
-rw-r--r-- | Swiften/Network/BoostConnection.cpp | 19 | ||||
-rw-r--r-- | Swiften/Network/Connection.h | 2 |
2 files changed, 15 insertions, 6 deletions
diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp index f837b50..d374221 100644 --- a/Swiften/Network/BoostConnection.cpp +++ b/Swiften/Network/BoostConnection.cpp @@ -59,7 +59,7 @@ void BoostConnection::connect(const String& domain) { boost::bind(&BoostConnection::handleConnectFinished, shared_from_this(), boost::asio::placeholders::error)); } catch (const DomainNameResolveException& e) { - onError(DomainNameResolveError); + onDisconnected(DomainNameResolveError); } } @@ -79,7 +79,7 @@ void BoostConnection::handleConnectFinished(const boost::system::error_code& err doRead(); } else if (error != boost::asio::error::operation_aborted) { - MainEventLoop::postEvent(boost::bind(boost::ref(onError), ConnectionError), shared_from_this()); + MainEventLoop::postEvent(boost::bind(boost::ref(onDisconnected), ConnectionError), shared_from_this()); } } @@ -94,14 +94,23 @@ void BoostConnection::handleSocketRead(const boost::system::error_code& error, s MainEventLoop::postEvent(boost::bind(boost::ref(onDataRead), ByteArray(&readBuffer_[0], bytesTransferred)), shared_from_this()); doRead(); } + else if (error == boost::asio::error::eof) { + MainEventLoop::postEvent(boost::bind(boost::ref(onDisconnected), boost::optional<Error>()), shared_from_this()); + } else if (error != boost::asio::error::operation_aborted) { - MainEventLoop::postEvent(boost::bind(boost::ref(onError), ReadError), shared_from_this()); + MainEventLoop::postEvent(boost::bind(boost::ref(onDisconnected), ReadError), shared_from_this()); } } void BoostConnection::handleDataWritten(const boost::system::error_code& error) { - if (error && error != boost::asio::error::operation_aborted) { - MainEventLoop::postEvent(boost::bind(boost::ref(onError), WriteError), shared_from_this()); + if (!error) { + return; + } + if (error == boost::asio::error::eof) { + MainEventLoop::postEvent(boost::bind(boost::ref(onDisconnected), boost::optional<Error>()), shared_from_this()); + } + else if (error && error != boost::asio::error::operation_aborted) { + MainEventLoop::postEvent(boost::bind(boost::ref(onDisconnected), WriteError), shared_from_this()); } } diff --git a/Swiften/Network/Connection.h b/Swiften/Network/Connection.h index 16d5d7b..c34c21d 100644 --- a/Swiften/Network/Connection.h +++ b/Swiften/Network/Connection.h @@ -26,7 +26,7 @@ namespace Swift { public: boost::signal<void ()> onConnected; - boost::signal<void (Error)> onError; + boost::signal<void (const boost::optional<Error>&)> onDisconnected; boost::signal<void (const ByteArray&)> onDataRead; }; } |