summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/client/net/serverconnection.cpp59
-rw-r--r--src/client/net/serverconnection.h3
-rw-r--r--src/client/toolbar/toolbar.cpp10
-rw-r--r--src/client/toolbar/toolbar.h2
-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
8 files changed, 78 insertions, 37 deletions
diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp
index 849f43b..6858f54 100644
--- a/src/client/net/serverconnection.cpp
+++ b/src/client/net/serverconnection.cpp
@@ -15,7 +15,7 @@
#define CHALLENGE_LEN 20
ServerConnection::ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash) :
- QObject(NULL), _jpegQuality(80), _authed(0), _sessionName(sessionName), _certHash(certHash)
+ QObject(NULL), _timerDelete(0), _jpegQuality(80), _authed(0), _sessionName(sessionName), _certHash(certHash)
{
_socket = new QSslSocket();
_blank = new BlankScreen();
@@ -37,7 +37,12 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons
ServerConnection::~ServerConnection()
{
- this->disconnectFromServer();
+ if (_socket != NULL)
+ {
+ qCritical("**** SOCKET DELETE IN DESTRUCTOR");
+ _socket->deleteLater();
+ }
+ qDebug("*** Server connection destroyed.");
_blank->deleteLater();
_blank = NULL;
}
@@ -56,16 +61,19 @@ void ServerConnection::sendMessage(NetworkMessage& message)
void ServerConnection::disconnectFromServer()
{
- if (_socket == NULL)
- return;
- qDebug("Closing connection to server");
- VncServer::instance()->stop();
- emit closeVnc();
- _socket->blockSignals(true);
- _socket->abort();
- _socket->deleteLater();
- _socket = NULL;
- this->deleteLater();
+ if (_timerDelete == 0)
+ {
+ VncServer::instance()->stop();
+ emit closeVnc();
+ emit disconnected();
+ _timerDelete = startTimer(500);
+ qDebug("Closing connection to server");
+ if (_socket != NULL)
+ {
+ _socket->blockSignals(true);
+ _socket->abort();
+ }
+ }
}
void ServerConnection::handleMsg()
@@ -236,11 +244,28 @@ void ServerConnection::handleMsg()
void ServerConnection::timerEvent(QTimerEvent *event)
{
- if (_timerId == 0)
- return;
- killTimer(_timerId);
- _timerId = 0;
- this->disconnectFromServer();
+ if (event->timerId() == _timerId)
+ {
+ killTimer(_timerId);
+ _timerId = 0;
+ this->disconnectFromServer();
+ }
+ 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());
}
/**
diff --git a/src/client/net/serverconnection.h b/src/client/net/serverconnection.h
index afb8204..7dddf5e 100644
--- a/src/client/net/serverconnection.h
+++ b/src/client/net/serverconnection.h
@@ -14,7 +14,7 @@ Q_OBJECT
private:
QSslSocket *_socket;
BlankScreen *_blank;
- int _timerId;
+ int _timerId, _timerDelete;
int _jpegQuality;
int _authed;
@@ -56,6 +56,7 @@ signals:
void openVnc(const QString& host, int port, const QString& passwd, bool ro, bool fullscreen, const QString& caption, const int clientId);
void closeVnc();
void stateChange(ConnectWindow::ConnectionState state);
+ void disconnected();
};
diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp
index 416a68f..6fe7432 100644
--- a/src/client/toolbar/toolbar.cpp
+++ b/src/client/toolbar/toolbar.cpp
@@ -158,11 +158,11 @@ void Toolbar::timerEvent(QTimerEvent* event)
* Slots
*/
-void Toolbar::onDisconnected(QObject* connection)
+void Toolbar::onDisconnected()
{
- if (connection != _connection)
- qDebug("onDisconnect pointer mismatch!");
_connectWindow->setConnected(false);
+ if (_connection != NULL)
+ _connection->blockSignals(true);
_connection = NULL;
lblStatus->setStyleSheet("color:red");
lblStatus->setText(tr("Offline"));
@@ -175,12 +175,12 @@ void Toolbar::onConnected(ServerConnection* connection)
//
if (_connection != NULL)
{
- disconnect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onDisconnected(QObject*)));
+ disconnect(_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
_connection->blockSignals(true);
_connection->disconnectFromServer();
}
_connection = connection;
- connect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onDisconnected(QObject*)));
+ connect(_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
connect(_connection, SIGNAL(openVnc(const QString&, int, const QString&, bool, bool, const QString&, const int)),
_vnc, SLOT(open(const QString&, int, const QString&, bool, bool, const QString&, const int)));
connect(_connection, SIGNAL(closeVnc()), _vnc, SLOT(close()));
diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h
index 0ce4d2b..8887ca7 100644
--- a/src/client/toolbar/toolbar.h
+++ b/src/client/toolbar/toolbar.h
@@ -68,7 +68,7 @@ protected:
*/
private slots:
- void onDisconnected(QObject* connection);
+ void onDisconnected();
void onConnected(ServerConnection* connection);
void onDoDisconnect();
void onQuit();
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