Commit 50bba6b7 authored by Eskil Abrahamsen-Blomfeldt's avatar Eskil Abrahamsen-Blomfeldt
Browse files

Fix threading

We were not actually doing anything on the client thread, since
the vnc client had been created as a child of the server, and
thus could not be moved. Fixing this revealed a bug in the
cleanup logic. We need to make sure we deleteLater() the
client objects and we need to quit and delete the client
thread from the main thread, after the client has been
deleted.
parent ac0231a8
......@@ -237,7 +237,7 @@ public:
int QVncClient::sharedButtonState = Qt::NoButton;
QVncClient::QVncClient(QVncServer *server)
: QObject(server)
: QObject(nullptr)
, m_server(server)
, m_supportCopyRect(false)
, m_supportRRE(false)
......@@ -282,10 +282,6 @@ void QVncClient::initializeConnection()
QVncClient::~QVncClient()
{
m_clientThread->quit();
m_clientThread->wait(2000);
delete m_clientThread;
delete m_encoder;
delete m_dirtyMap;
......@@ -721,7 +717,7 @@ void QVncClient::readClient()
void QVncClient::discardClient()
{
m_state = Disconnected;
m_server->discardClient(this);
QMetaObject::invokeMethod(m_server, "discardClient", Q_ARG(QObject*, this));
}
void QVncClient::checkUpdate()
......
......@@ -33,6 +33,7 @@
#include <QtCore/private/qobject_p.h>
#include <QtCore/qreadwritelock.h>
#include <QtCore/qthread.h>
#include <QtGui/qimage.h>
#include <QtGui/qguiapplication.h>
#include <QtNetwork/qtcpsocket.h>
......@@ -103,7 +104,10 @@ void QVncServer::incomingConnection(qintptr handle)
QVncServer::~QVncServer()
{
Q_D(QVncServer);
qDeleteAll(d->clients);
while (!d->clients.isEmpty())
discardClient(d->clients.first());
delete d->clientCursor;
}
QRect QVncServer::screenGeometry() const
......@@ -128,14 +132,25 @@ void QVncServer::setDirty()
//qvnc_screen->clearDirty();
}
void QVncServer::discardClient(QVncClient *client)
void QVncServer::discardClient(QObject *c)
{
Q_D(QVncServer);
d->clients.removeOne(client);
client->deleteLater();
if (d->clientCursor != nullptr)
d->clientCursor->removeClient(client);
setIsConnected(!d->clients.isEmpty());
QVncClient *client = qobject_cast<QVncClient *>(c);
if (client != nullptr) {
d->clients.removeOne(client);
if (d->clientCursor != nullptr)
d->clientCursor->removeClient(client);
setIsConnected(!d->clients.isEmpty());
{
QThread *t = client->thread();
client->deleteLater();
t->quit();
t->wait(1000);
delete t;
}
}
}
bool QVncServer::isConnected() const
......
......@@ -84,13 +84,13 @@ protected:
private Q_SLOTS:
void init();
void discardClient(QObject *client);
private:
friend class QVncClient;
void setDirty();
void setIsConnected(bool newIsConnected);
void discardClient(QVncClient *client);
void enableClientCursor(QVncClient *client);
QVncClientCursor *clientCursor() const;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment