From 49f3903f316ab7363b4543615d3231e1407a67ab Mon Sep 17 00:00:00 2001 From: sr Date: Wed, 6 Feb 2013 19:21:04 +0100 Subject: [SERVER] Add "stop projection" button [SERVER] Don't show error message when VNC server stops as expected [SERVER/CLIENT] Implement connection timeout of 15 seconds --- src/server/net/client.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/server/net/client.cpp') diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp index d6002a6..3adeeaa 100644 --- a/src/server/net/client.cpp +++ b/src/server/net/client.cpp @@ -24,7 +24,6 @@ Client::Client(QSslSocket* socket) : { assert(socket != NULL); _id = ++_clientIdCounter; - _pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS; _ip = _socket->peerAddress().toString(); qDebug("*** Client %s created.", qPrintable(_ip)); // Connect important signals @@ -42,6 +41,8 @@ Client::Client(QSslSocket* socket) : _toClient.writeMessage(_socket); // give client 3 seconds to complete handshake _timerIdAuthTimeout = startTimer(3000); + _timerPingTimeout = startTimer(5000); + _pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS; } Client::~Client() @@ -56,7 +57,16 @@ Client::~Client() void Client::timerEvent(QTimerEvent* event) { - if (event->timerId() == _timerIdAuthTimeout) + if (event->timerId() == _timerPingTimeout) + { + if (_pingTimeout < QDateTime::currentMSecsSinceEpoch()) + { + qDebug() << "Client" << _ip << "has a ping timeout."; + killTimer(_timerPingTimeout); + this->disconnect(); + } + } + else if (event->timerId() == _timerIdAuthTimeout) { // Client did not send login request within 3 seconds killTimer(_timerIdAuthTimeout); @@ -108,7 +118,6 @@ void Client::requestThumb(const int width, const int height) void Client::onDataArrival() { - _pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS; // if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState) { @@ -153,6 +162,7 @@ void Client::onError(QAbstractSocket::SocketError errcode) void Client::handleMsg() { + _pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS; const QString &id = _fromClient.getFieldString(_ID); if (id.isEmpty()) { -- cgit v1.2.3-55-g7522