diff options
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; }; } |