From 7a83179d3135b29b087aebaad5a8570b0e2e9495 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Mon, 23 May 2022 13:30:10 +0300 Subject: [PATCH] RpcManager: Setup client on reconnection --- src/ui/control/controlmanager.cpp | 1 - src/ui/control/controlworker.cpp | 1 + src/ui/control/controlworker.h | 1 + src/ui/rpc/rpcmanager.cpp | 8 ++++++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ui/control/controlmanager.cpp b/src/ui/control/controlmanager.cpp index 80aedbcd..fabf8673 100644 --- a/src/ui/control/controlmanager.cpp +++ b/src/ui/control/controlmanager.cpp @@ -55,7 +55,6 @@ ControlWorker *ControlManager::newServiceClient(QObject *parent) const connect(w, &ControlWorker::requestReady, this, &ControlManager::processRequest); w->setServerName(getServerName(/*isService=*/true)); - w->connectToServer(); return w; } diff --git a/src/ui/control/controlworker.cpp b/src/ui/control/controlworker.cpp index 3195b3de..f2236ace 100644 --- a/src/ui/control/controlworker.cpp +++ b/src/ui/control/controlworker.cpp @@ -110,6 +110,7 @@ void ControlWorker::setupForAsync() qCWarning(LC) << "Client error:" << id() << socketError << errorString(); close(); }); + connect(socket(), &QLocalSocket::connected, this, &ControlWorker::connected); connect(socket(), &QLocalSocket::disconnected, this, &ControlWorker::onDisconnected); connect(socket(), &QLocalSocket::readyRead, this, &ControlWorker::processRequest); } diff --git a/src/ui/control/controlworker.h b/src/ui/control/controlworker.h index c5a7fc70..8e1444c4 100644 --- a/src/ui/control/controlworker.h +++ b/src/ui/control/controlworker.h @@ -50,6 +50,7 @@ public: static QVariantList buildArgs(const QStringList &list); signals: + void connected(); void disconnected(); void requestReady(Control::Command command, const QVariantList &args); diff --git a/src/ui/rpc/rpcmanager.cpp b/src/ui/rpc/rpcmanager.cpp index d254bb92..ec3f52ed 100644 --- a/src/ui/rpc/rpcmanager.cpp +++ b/src/ui/rpc/rpcmanager.cpp @@ -368,9 +368,12 @@ void RpcManager::setupClient() auto controlManager = IoC()->setUpDependency(); m_client = controlManager->newServiceClient(this); - client()->setIsTryReconnect(true); - invokeOnServer(Control::Rpc_RpcManager_initClient); + connect(client(), &ControlWorker::connected, this, + [&] { invokeOnServer(Control::Rpc_RpcManager_initClient); }); + + client()->setIsTryReconnect(true); + client()->connectToServer(); } void RpcManager::closeClient() @@ -489,6 +492,7 @@ bool RpcManager::processManagerRpc(const ProcessCommandArgs &p) { if (commandRequiresValidation(p.command) && !checkClientValidated(p.worker)) { p.errorMessage = "Client is not validated"; + sendResult(p.worker, false); return false; }