aboutsummaryrefslogtreecommitdiff
path: root/src/TcpTasks/SyncClient/onsyncdisconnect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/TcpTasks/SyncClient/onsyncdisconnect.cpp')
-rw-r--r--src/TcpTasks/SyncClient/onsyncdisconnect.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/TcpTasks/SyncClient/onsyncdisconnect.cpp b/src/TcpTasks/SyncClient/onsyncdisconnect.cpp
new file mode 100644
index 0000000..4bc8eac
--- /dev/null
+++ b/src/TcpTasks/SyncClient/onsyncdisconnect.cpp
@@ -0,0 +1,49 @@
+#include "syncclient.h"
+
+void SyncClient::onSyncDisconnect()
+{
+ // remote host closed the connection (typically occurs after receiving the list from remote host)
+ if (_tcpSocket.error() == QAbstractSocket::RemoteHostClosedError )
+ {
+ _coreObject->Log.logEvent("tcp", QStringLiteral("disconnected from %1").arg(_clientLabel) );
+ }
+
+ // timer already stopped or a timeout occurred
+ if ( ! _timeOut.isActive() or _tcpSocket.error() == QAbstractSocket::SocketTimeoutError)
+ {
+ _coreObject->Log.logEvent("warning", QStringLiteral("timeout while attempting to sync with %1 (1)").arg(_clientLabel));
+ }
+
+ // an error occured and is reported, excluding...
+ if ( _tcpSocket.error() != QAbstractSocket::RemoteHostClosedError and // ...regular disconnect caught above
+ _tcpSocket.error() != QAbstractSocket::SocketTimeoutError and // ...timeout caught above
+ _tcpSocket.error() != QAbstractSocket::UnknownSocketError ) // ...QTimer timeout does not leave an errorcode (defaults to unknown error)
+ {
+ _coreObject->Log.logEvent("warning", QStringLiteral("error while syncing with %1: %2").arg(_clientLabel, _tcpSocket.errorString()));
+ }
+
+ // stop timer if necessary and delete this client
+ _timeOut.stop();
+ this->deleteLater();
+}
+
+void SyncClient::onSyncTimeOut()
+{
+ // if no error was specified while timer expired, there was a connection timeout
+ if ( _tcpSocket.error() == QAbstractSocket::UnknownSocketError )
+ {
+ _coreObject->Log.logEvent("warning", QStringLiteral("timeout while attempting to sync with %1 (2)").arg(_clientLabel));
+ }
+
+ // other errors, like establishing connection/refused
+ if ( _tcpSocket.error() != QAbstractSocket::UnknownSocketError )
+ {
+ _coreObject->Log.logEvent("warning", QStringLiteral("error while syncing with %1: %2").arg(_clientLabel, _tcpSocket.errorString()));
+ }
+
+ // stop timer and close socket
+ _timeOut.stop();
+ _coreObject->Log.logEvent("tcp", QStringLiteral("%1 scheduled for deletion").arg(_clientLabel) );
+ _tcpSocket.disconnectFromHost();
+ this->deleteLater();
+}