summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorsr2013-02-05 19:00:11 +0100
committersr2013-02-05 19:00:11 +0100
commit62fb9fd2b4d6e1d8e0c06f70bb7ba08b1f286be7 (patch)
tree5a19e024633de3ccdaf2f182b75374d74bac5dbf /src/server
parent[SHARED] Add missing error message if network message parsing fails (diff)
downloadpvs2-62fb9fd2b4d6e1d8e0c06f70bb7ba08b1f286be7.tar.gz
pvs2-62fb9fd2b4d6e1d8e0c06f70bb7ba08b1f286be7.tar.xz
pvs2-62fb9fd2b4d6e1d8e0c06f70bb7ba08b1f286be7.zip
[SERVER/CLIENT] Wait for connection to close properly before deleting socket object
Diffstat (limited to 'src/server')
-rw-r--r--src/server/connectionframe/connectionframe.cpp5
-rw-r--r--src/server/connectionframe/connectionframe.h2
-rw-r--r--src/server/net/client.cpp31
-rw-r--r--src/server/net/client.h3
4 files changed, 28 insertions, 13 deletions
diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp
index 6bfce81..05e24a4 100644
--- a/src/server/connectionframe/connectionframe.cpp
+++ b/src/server/connectionframe/connectionframe.cpp
@@ -97,7 +97,7 @@ void ConnectionFrame::setSize(int width, int height)
void ConnectionFrame::assignClient(Client* client)
{
assert(_client == NULL);
- connect(client, SIGNAL(destroyed(QObject*)), this, SLOT(onClientDisconnected(QObject*)));
+ connect(client, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()));
connect(client, SIGNAL(thumbUpdated(Client*, const QPixmap&)), this, SLOT(onThumbUpdated(Client*, const QPixmap&)));
connect(client, SIGNAL(vncServerStateChange(Client*)), this, SLOT(onVncServerStateChange(Client*)));
connect(client, SIGNAL(vncClientStateChange(Client*)), this, SLOT(onVncClientStateChange(Client*)));
@@ -254,9 +254,8 @@ void ConnectionFrame::updateColor()
* Slots
*/
-void ConnectionFrame::onClientDisconnected(QObject* client)
+void ConnectionFrame::onClientDisconnected()
{
- assert(client == _client);
if (_timerId != 0)
{
killTimer(_timerId);
diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h
index ccb32a8..cc7ab05 100644
--- a/src/server/connectionframe/connectionframe.h
+++ b/src/server/connectionframe/connectionframe.h
@@ -68,7 +68,7 @@ signals:
void clicked(ConnectionFrame* frame);
private slots:
- void onClientDisconnected(QObject* client);
+ void onClientDisconnected();
void onThumbUpdated(Client* client, const QPixmap& thumb);
void onVncServerStateChange(Client* client);
void onVncClientStateChange(Client* client);
diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp
index fdabb99..12b28a0 100644
--- a/src/server/net/client.cpp
+++ b/src/server/net/client.cpp
@@ -19,7 +19,7 @@
ClientId Client::_clientIdCounter = 0;
Client::Client(QSslSocket* socket) :
- _socket(socket), _authed(0), _desiredProjectionSource(0), _isProjectionSource(false),
+ _socket(socket), _authed(0), _timerDelete(0), _desiredProjectionSource(0), _isProjectionSource(false),
_currentProjectionSource(0), _vncPort(0), _activeVncClient(false), _isTutor(false)
{
assert(socket != NULL);
@@ -48,7 +48,7 @@ Client::~Client()
{
if (_socket != NULL)
{
- qDebug("**** DELETE IN DESTRUCTOR");
+ qCritical("**** SOCKET DELETE IN DESTRUCTOR");
_socket->deleteLater();
}
qDebug("*** Client %s destroyed.", qPrintable(_ip));
@@ -63,6 +63,22 @@ void Client::timerEvent(QTimerEvent* event)
_timerIdAuthTimeout = 0;
this->disconnect();
}
+ else if (event->timerId() == _timerDelete)
+ {
+ if (_socket == NULL || _socket->state() == QAbstractSocket::UnconnectedState)
+ {
+ if (_socket != NULL)
+ _socket->deleteLater();
+ _socket = NULL;
+ killTimer(_timerDelete);
+ this->deleteLater();
+ return;
+ }
+ _socket->abort();
+ qDebug("A socket is still pending...");
+ }
+ else
+ killTimer(event->timerId());
}
void Client::sendMessage(NetworkMessage& message)
@@ -113,9 +129,9 @@ void Client::onDataArrival()
if (_fromClient.readComplete()) // message is complete
{
this->handleMsg();
+ _fromClient.reset();
if (_socket == NULL)
return;
- _fromClient.reset();
}
}
}
@@ -243,7 +259,7 @@ void Client::handleMsg()
{ // Challenge reply is invalid, drop client
_toClient.buildErrorMessage("Challenge reply invalid.");
_toClient.writeMessage(_socket);
- this->deleteLater();
+ this->disconnect();
return;
}
// Now answer to challenge by client
@@ -294,13 +310,12 @@ void Client::setTutor(bool enable)
void Client::disconnect()
{
- if (_socket != NULL)
+ if (_timerDelete == 0)
{
+ emit disconnected();
+ _timerDelete = startTimer(500);
qDebug("*** Client %s disconnected.", qPrintable(_ip));
_socket->blockSignals(true);
_socket->abort();
- _socket->deleteLater();
- _socket = NULL;
- this->deleteLater();
}
}
diff --git a/src/server/net/client.h b/src/server/net/client.h
index 2cdfb23..d058398 100644
--- a/src/server/net/client.h
+++ b/src/server/net/client.h
@@ -33,7 +33,7 @@ private:
QByteArray _challenge;
qint64 _pingTimeout;
NetworkMessage _toClient, _fromClient;
- int _timerIdAuthTimeout;
+ int _timerIdAuthTimeout, _timerDelete;
ClientId _id; // this client's unique id
@@ -94,6 +94,7 @@ signals:
void thumbUpdated(Client* client, const QPixmap& thumb);
void vncServerStateChange(Client* client);
void vncClientStateChange(Client* client);
+ void disconnected();
private slots:
void onSslErrors(const QList<QSslError> & errors); // triggered for errors that occur during SSL negotiation