diff options
| author | Dark1-dev <shansarkar272@gmail.com> | 2023-03-01 21:30:57 +0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-01 21:30:57 +0600 |
| commit | 60a301a93b6057bb2c54ac04a7c38c38389037b3 (patch) | |
| tree | b09c5f8bc0045828c660654d8ed6744663856202 /src/TcpTasks/SyncClient/onsyncdisconnect.cpp | |
| parent | c784240d1af68dbd8d0466822b34fd05d6ccdda1 (diff) | |
| download | Masterserver-Qt5-60a301a93b6057bb2c54ac04a7c38c38389037b3.tar.gz Masterserver-Qt5-60a301a93b6057bb2c54ac04a7c38c38389037b3.zip | |
Add files via upload
Diffstat (limited to 'src/TcpTasks/SyncClient/onsyncdisconnect.cpp')
| -rw-r--r-- | src/TcpTasks/SyncClient/onsyncdisconnect.cpp | 49 |
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(); +} |
