Skip to content

Commit

Permalink
read entire signal, don't allocate fixed size buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
marazmista committed Mar 9, 2019
1 parent ae026bd commit 65166ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
15 changes: 5 additions & 10 deletions radeon-profile-daemon/rpdthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ rpdThread::rpdThread() : QThread(),
void rpdThread::newConn() {
qInfo() << "Connecting to the client";
signalReceiver = daemonServer.nextPendingConnection();
connect(signalReceiver,SIGNAL(readyRead()),this,SLOT(decodeSignal()));
connect(signalReceiver,SIGNAL(readyRead()),this,SLOT(readSignalAndPerformTask()));
connect(signalReceiver,SIGNAL(disconnected()),this,SLOT(disconnected()));

connectionConfirmed = true;
Expand Down Expand Up @@ -77,6 +77,7 @@ void rpdThread::sendMessage(const QString &msg)
{
QByteArray feedback;
QDataStream out(&feedback, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_7);

out << msg;

Expand All @@ -99,13 +100,6 @@ void rpdThread::checkConnection() {
sendMessage("7#1#");
}

void rpdThread::decodeSignal() {
char signal[1024] = {0};

signalReceiver->read(signal,signalReceiver->bytesAvailable());
performTask(QString(signal));
}

void rpdThread::onTimer() {
if (signalReceiver->state() == QLocalSocket::ConnectedState)
readData();
Expand All @@ -121,8 +115,9 @@ void rpdThread::onTimer() {
// 5 - stop timer
// 6 - shared mem key
// 7 - alive msg
void rpdThread::performTask(const QString &signal) {
qDebug() << "Performing task: " << signal;
void rpdThread::readSignalAndPerformTask() {
const auto signal = QString(signalReceiver->readAll());
qDebug() << "Received signal: " << signal;

if (signal.isEmpty()) {
qWarning() << "Received empty signal";
Expand Down
5 changes: 2 additions & 3 deletions radeon-profile-daemon/rpdthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define SIGNAL_SHAREDMEM_KEY '6'
#define SIGNAL_ALIVE '7'

const QString appVersion = "20190301";
const QString appVersion = "20190309";
const QString serverName = "radeon-profile-daemon-server";

class rpdThread : public QThread
Expand All @@ -44,10 +44,10 @@ class rpdThread : public QThread

public slots:
void newConn();
void decodeSignal();
void onTimer();
void disconnected();
void checkConnection();
void readSignalAndPerformTask();

private:
QLocalSocket *signalReceiver;
Expand All @@ -60,7 +60,6 @@ public slots:

void readData();
bool setNewValue(const QString &filePath, const QString &newValue);
void performTask(const QString &signal);
bool configure(const QString &type, const QString &filePath);
void configureSharedMem(const QString &key);
bool checkRequiredCommandLength(unsigned required, unsigned currentIndex, unsigned size);
Expand Down

0 comments on commit 65166ba

Please sign in to comment.