Commit 9d5d45c7 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

PendingRfbClient: Include its own QSocketNotifier

Instead of keeping it in its only subclass PendingInvitationsRfbClient.
The notifier is necessary for pending clients overall and entirely
unrelated to the task of PendingInvitationsRfbClient.
parent b4eccc21
......@@ -52,10 +52,6 @@ PendingInvitationsRfbClient::PendingInvitationsRfbClient(rfbClientPtr client, QO
d(new Private(client))
{
d->client->clientGoneHook = clientGoneHookNoop;
d->notifier = new QSocketNotifier(client->sock, QSocketNotifier::Read, this);
d->notifier->setEnabled(true);
connect(d->notifier, &QSocketNotifier::activated,
this, &PendingInvitationsRfbClient::onSocketActivated);
}
PendingInvitationsRfbClient::~PendingInvitationsRfbClient()
......@@ -90,39 +86,6 @@ void PendingInvitationsRfbClient::processNewClient()
}
}
void PendingInvitationsRfbClient::onSocketActivated()
{
//Process not only one, but all pending messages.
//poll() idea/code copied from vino:
// Copyright (C) 2003 Sun Microsystems, Inc.
// License: GPL v2 or later
struct pollfd pollfd = { d->client->sock, POLLIN|POLLPRI, 0 };
while(poll(&pollfd, 1, 0) == 1) {
if(d->client->state == rfbClientRec::RFB_INITIALISATION) {
d->notifier->setEnabled(false);
//Client is Authenticated
processNewClient();
break;
}
rfbProcessClientMessage(d->client);
//This is how we handle disconnection.
//if rfbProcessClientMessage() finds out that it can't read the socket,
//it closes it and sets it to -1. So, we just have to check this here
//and call rfbClientConnectionGone() if necessary. This will call
//the clientGoneHook which in turn will remove this RfbClient instance
//from the server manager and will call deleteLater() to delete it
if (d->client->sock == -1) {
qCDebug(KRFB) << "disconnected from socket signal";
d->notifier->setEnabled(false);
rfbClientConnectionGone(d->client);
break;
}
}
}
bool PendingInvitationsRfbClient::checkPassword(const QByteArray & encryptedPassword)
{
qCDebug(KRFB) << "about to start authentication";
......
......@@ -37,7 +37,6 @@ public:
protected Q_SLOTS:
void processNewClient() override;
virtual void onSocketActivated();
bool checkPassword(const QByteArray & encryptedPassword) override;
private Q_SLOTS:
......
......@@ -21,7 +21,6 @@
#include "invitationsrfbserver.h"
#include "invitationsrfbclient.h"
#include "krfbconfig.h"
#include "rfbservermanager.h"
#include "krfbdebug.h"
#include <QTimer>
#include <QApplication>
......
......@@ -170,8 +170,13 @@ void RfbClient::update()
PendingRfbClient::PendingRfbClient(rfbClientPtr client, QObject *parent)
: QObject(parent), m_rfbClient(client)
, m_notifier(new QSocketNotifier(client->sock, QSocketNotifier::Read, this))
{
m_rfbClient->clientData = this;
m_notifier->setEnabled(true);
connect(m_notifier, &QSocketNotifier::activated,
this, &PendingRfbClient::onSocketActivated);
}
PendingRfbClient::~PendingRfbClient()
......@@ -230,3 +235,35 @@ bool PendingRfbClient::vncAuthCheckPassword(const QByteArray& password, const QB
rfbEncryptBytes(challenge, passwd);
return memcmp(challenge, encryptedPassword.constData(), encryptedPassword.size()) == 0;
}
void PendingRfbClient::onSocketActivated()
{
//Process not only one, but all pending messages.
//poll() idea/code copied from vino:
// Copyright (C) 2003 Sun Microsystems, Inc.
// License: GPL v2 or later
struct pollfd pollfd = { m_rfbClient->sock, POLLIN|POLLPRI, 0 };
while(poll(&pollfd, 1, 0) == 1) {
if(m_rfbClient->state == rfbClientRec::RFB_INITIALISATION) {
m_notifier->setEnabled(false);
//Client is Authenticated
processNewClient();
break;
}
rfbProcessClientMessage(m_rfbClient);
//This is how we handle disconnection.
//if rfbProcessClientMessage() finds out that it can't read the socket,
//it closes it and sets it to -1. So, we just have to check this here
//and call rfbClientConnectionGone() if necessary. This will call
//the clientGoneHook which in turn will remove this RfbClient instance
//from the server manager and will call deleteLater() to delete it
if (m_rfbClient->sock == -1) {
qCDebug(KRFB) << "disconnected from socket signal";
m_notifier->setEnabled(false);
rfbClientConnectionGone(m_rfbClient);
break;
}
}
}
......@@ -23,6 +23,8 @@
#include "rfb.h"
#include <QObject>
class QSocketNotifier;
class RfbClient : public QObject
{
Q_OBJECT
......@@ -104,6 +106,11 @@ protected:
bool vncAuthCheckPassword(const QByteArray & password, const QByteArray & encryptedPassword) const;
rfbClientPtr m_rfbClient;
private:
void onSocketActivated();
QSocketNotifier *const m_notifier;
};
#endif // RFBCLIENT_H
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