fix: prevent daemon ipc client from sending multiple messages at the same time
This commit is contained in:
parent
c6544dd4eb
commit
abfcc59f22
2 changed files with 5 additions and 0 deletions
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
|
#include <QMutexLocker>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
|
@ -79,6 +80,7 @@ bool DaemonIpcClient::connectToServer()
|
||||||
|
|
||||||
void DaemonIpcClient::disconnectFromServer()
|
void DaemonIpcClient::disconnectFromServer()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
m_state = State::Disconnecting;
|
m_state = State::Disconnecting;
|
||||||
qDebug() << "daemon ipc client disconnecting from server";
|
qDebug() << "daemon ipc client disconnecting from server";
|
||||||
m_socket->disconnectFromServer();
|
m_socket->disconnectFromServer();
|
||||||
|
|
@ -116,6 +118,7 @@ void DaemonIpcClient::handleErrorOccurred()
|
||||||
|
|
||||||
bool DaemonIpcClient::sendMessage(const QString &message, const QString &expectAck, const bool expectConnected)
|
bool DaemonIpcClient::sendMessage(const QString &message, const QString &expectAck, const bool expectConnected)
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
if (expectConnected && !isConnected()) {
|
if (expectConnected && !isConnected()) {
|
||||||
qWarning() << "cannot send command, ipc client not connected";
|
qWarning() << "cannot send command, ipc client not connected";
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class QLocalSocket;
|
class QLocalSocket;
|
||||||
|
|
@ -54,6 +55,7 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLocalSocket *m_socket;
|
QLocalSocket *m_socket;
|
||||||
|
QMutex m_mutex;
|
||||||
State m_state{State::Unconnected};
|
State m_state{State::Unconnected};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue