summaryrefslogtreecommitdiffstats
path: root/src/net/pvsServerConnection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/pvsServerConnection.cpp')
-rw-r--r--src/net/pvsServerConnection.cpp22
1 files changed, 12 insertions, 10 deletions
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 <QTime>
//#define verbose
PVSServerConnection::PVSServerConnection(PVS *parent) : QObject(parent)
@@ -62,7 +63,7 @@ bool PVSServerConnection::connectToServer(PVSDiscoveredServer* server, QString p
SLOT(sslErrors(const QList<QSslError> &))
);
_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);