summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohann Latocha2011-06-02 00:29:37 +0200
committerJohann Latocha2011-06-02 00:29:37 +0200
commite001d2a05ac722611fcd19e7678f96cc22156cb9 (patch)
tree82bfd9dc3f312fb4b0335ef2011365d4c39be0c3
parentEnhancement #821 (diff)
downloadpvs-e001d2a05ac722611fcd19e7678f96cc22156cb9.tar.gz
pvs-e001d2a05ac722611fcd19e7678f96cc22156cb9.tar.xz
pvs-e001d2a05ac722611fcd19e7678f96cc22156cb9.zip
Defect #819
-rw-r--r--src/net/pvsClientConnection.cpp1
-rw-r--r--src/net/pvsDiscoveredServer.cpp5
-rw-r--r--src/net/pvsListenServer.cpp3
-rw-r--r--src/net/pvsServerConnection.cpp22
-rw-r--r--src/net/pvsServerConnection.h2
-rw-r--r--src/setup.h2
6 files changed, 18 insertions, 17 deletions
diff --git a/src/net/pvsClientConnection.cpp b/src/net/pvsClientConnection.cpp
index 5354e95..9f66562 100644
--- a/src/net/pvsClientConnection.cpp
+++ b/src/net/pvsClientConnection.cpp
@@ -162,7 +162,6 @@ void PVSClientConnection::setID(unsigned int id)
void PVSClientConnection::ping()
{
- // still needs flag/timer to check for a ping timeout (and a reply from the client)
this->push_back_send(PVSMsg(PVSCOMMAND, "PING", "HELLO?", _id));
}
diff --git a/src/net/pvsDiscoveredServer.cpp b/src/net/pvsDiscoveredServer.cpp
index efa1506..dae27b0 100644
--- a/src/net/pvsDiscoveredServer.cpp
+++ b/src/net/pvsDiscoveredServer.cpp
@@ -46,9 +46,8 @@ void PVSDiscoveredServer::ssl_Error( const QList<QSslError> & errors )
if (err.error() == QSslError::SelfSignedCertificate) {
continue; // Also, this will always be the case; we check the fingerprint later
}
- //ConsoleLog writeNetwork(err.errorString().toUtf8().data());
- //ConsoleLog writeNetwork("***** SSL ERROR, ABORTING *****");
- qDebug("Unhandled SSL Error in SD: %s", qPrintable(err.errorString()));
+ // http://doc.trolltech.com/4.7//qsslerror.html#SslError-enum
+ qDebug("Unhandled SSL Error %i: %s", err.error(), qPrintable(err.errorString()));
return;
}
_socket->ignoreSslErrors();
diff --git a/src/net/pvsListenServer.cpp b/src/net/pvsListenServer.cpp
index 1280a92..c50b25a 100644
--- a/src/net/pvsListenServer.cpp
+++ b/src/net/pvsListenServer.cpp
@@ -124,7 +124,7 @@ bool PVSListenServer::shutdown()
return false;
}
-// timer event, CLIENT_TIMEOUT interval
+// timer event, CLIENT_KEEPALIVE interval
void PVSListenServer::timerEvent(QTimerEvent *event)
{
if (!(_clients.empty()))
@@ -141,7 +141,6 @@ void PVSListenServer::timerEvent(QTimerEvent *event)
if (disconnectClient(client))
break; // list was modified, iterator not valid anymore
}
- qDebug() << client->lastData() << " " << refval;
if (client->lastData() < refval)
{ // ping timeout
qDebug("DEBUG: Ping timeout for client %s", qPrintable(client->getNameUser()));
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);
diff --git a/src/net/pvsServerConnection.h b/src/net/pvsServerConnection.h
index c6ef015..017e485 100644
--- a/src/net/pvsServerConnection.h
+++ b/src/net/pvsServerConnection.h
@@ -30,7 +30,6 @@ public:
return _socket != NULL && _socket->state() == QAbstractSocket::ConnectedState;
}
- void ping();
QString getServerName();
virtual void loadCommands();
@@ -95,6 +94,7 @@ private:
QByteArray _expectedFingerprint;
QString _name;
QString _passwd;
+ time_t _lastData;
};
#endif
diff --git a/src/setup.h b/src/setup.h
index 879db1c..1f058a9 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -12,5 +12,7 @@
#define CLIENT_KEEPALIVE 5000 // Clients ping rate
#define CLIENT_TIMEOUT 15000 // Timeout to check if clients are alive
+#define SERVER_KEEPALIVE 5000 // Server check rate
+#define SERVER_TIMEOUT 15000 // Timeout to check if server is alive
#endif