diff options
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/net/serverconnection.cpp | 59 | ||||
| -rw-r--r-- | src/client/net/serverconnection.h | 3 | ||||
| -rw-r--r-- | src/client/toolbar/toolbar.cpp | 10 | ||||
| -rw-r--r-- | src/client/toolbar/toolbar.h | 2 |
4 files changed, 50 insertions, 24 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(); |
