RpcManager: Setup client on reconnection

This commit is contained in:
Nodir Temirkhodjaev 2022-05-23 13:30:10 +03:00
parent e532ca8010
commit 7a83179d31
4 changed files with 8 additions and 3 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -50,6 +50,7 @@ public:
static QVariantList buildArgs(const QStringList &list);
signals:
void connected();
void disconnected();
void requestReady(Control::Command command, const QVariantList &args);

View File

@ -368,9 +368,12 @@ void RpcManager::setupClient()
auto controlManager = IoC()->setUpDependency<ControlManager>();
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;
}