From e001d2a05ac722611fcd19e7678f96cc22156cb9 Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Thu, 2 Jun 2011 00:29:37 +0200 Subject: Defect #819 --- src/net/pvsServerConnection.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/net/pvsServerConnection.cpp') diff --git a/src/net/pvsServerConnection.cpp b/src/net/pvsServerConnection.cpp index 2ec2e5d..bc4b482 100644 --- a/src/net/pvsServerConnection.cpp +++ b/src/net/pvsServerConnection.cpp @@ -7,6 +7,7 @@ #include "src/core/pvsChatClient.h" #include "src/util/serviceDiscoveryUtil.h" #include "src/net/pvsDiscoveredServer.h" +#include //#define verbose PVSServerConnection::PVSServerConnection(PVS *parent) : QObject(parent) @@ -62,7 +63,7 @@ bool PVSServerConnection::connectToServer(PVSDiscoveredServer* server, QString p SLOT(sslErrors(const QList &)) ); _socket->connectToHostEncrypted(host.toString(), port); - if (_timer == 0) _timer = startTimer(10000); + if (_timer == 0) _timer = startTimer(SERVER_KEEPALIVE); return true; // we really don't know yet if it will succeed since its async } @@ -89,10 +90,17 @@ void PVSServerConnection::disconnectFromServer() handleDisconnectInternal(); } +// timer event, SERVER_KEEPALIVE interval void PVSServerConnection::timerEvent(QTimerEvent *event) { - if (_socket != NULL && _socket->state() == QAbstractSocket::ConnectedState) return; - // TODO: Check for ping timeout + if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState) return; + time_t refval = time(NULL) - (SERVER_TIMEOUT/1000); + if (_lastData < refval) + { // ping timeout + qDebug("DEBUG: Ping timeout for server!"); + qDebug("DEBUG: Timeout was %i last response was %i", refval, _lastData); + disconnectFromServer(); + } } void PVSServerConnection::sendMessage(PVSMsg newMessage) @@ -105,11 +113,6 @@ void PVSServerConnection::sendMessage(PVSMsg newMessage) _socket->write(qba); } -void PVSServerConnection::ping() -{ - sendMessage(PVSMsg(PVSCOMMAND, "PING", "U THERE?"));; -} - QString PVSServerConnection::getServerName() { if (!isConnected()) return QString(); @@ -137,8 +140,7 @@ void PVSServerConnection::onPing(PVSMsg pingmsg) void PVSServerConnection::handleClientMsg(PVSMsg receiver) { - // FIXME: @SimonR, this line cuase problems with pvs in daemon mode and dbus - //qDebug("Got Message for this client: [%c][%s][%s]\n", (char)receiver.getType(), receiver.getIdent().toUtf8().data(), receiver.getMessage().toUtf8().data()); + _lastData = time(NULL); if (receiver.getType() == PVSCOMMAND) { _commandDispatcher.fire(receiver.getIdent(), receiver); -- cgit v1.2.3-55-g7522