aboutsummaryrefslogtreecommitdiff
path: root/src/TcpTasks/SyncClient/onsyncdisconnect.cpp
blob: 4bc8eacc4df09946835eb3e68f368db0edaf588a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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();
}