Fix: reconnect after server restart without reinstalling the loader
The S_SERVER_EXIT respawn fix previously lived in test.cpp, which a deployed TestRun.exe cannot pick up without reinstalling. Move the reconnect decision into ClientDll::IsStoped(): when the master instance is in S_SERVER_EXIT, report reconnectable immediately instead of waiting for live shared instances to drain, so the already-deployed loader reconnects against a hot-loaded DLL. Shared instances stay connected to their own servers, preserving the IsSharedRunning contract that the master's state change must not tear them down. Also guard the RUNNING_PARALLEL branch so re-entering StartClient on reconnect spawns parallel instances once instead of duplicating them. Co-Authored-By: deepseek-v4-pro
This commit is contained in:
1 parent
33986f4893
commit
d3a339247b
1 file changed
+16
-4
+16
-4
@@ -445,6 +445,11 @@ extern "C" __declspec(dllexport) void StopRun()
|
|||||||
// 是否成功停止
|
// 是否成功停止
|
||||||
extern "C" __declspec(dllexport) bool IsStoped()
|
extern "C" __declspec(dllexport) bool IsStoped()
|
||||||
{
|
{
|
||||||
|
// 主控端重启(S_SERVER_EXIT):主实例工作线程已结束,即使分享实例仍在运行,
|
||||||
|
// 也视为「可重连」。旧 TestRun 加载循环靠它立即重连,无需卸载/重装 TestRun.exe;
|
||||||
|
// 分享实例继续存活,不受主控端重启影响。
|
||||||
|
if (S_SERVER_EXIT == g_MyApp.g_bExit)
|
||||||
|
return true;
|
||||||
return g_MyApp.g_bThreadExit && ClientApp::GetCount() == 0;
|
return g_MyApp.g_bThreadExit && ClientApp::GetCount() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,10 +611,17 @@ DWORD WINAPI StartClient(LPVOID lParam)
|
|||||||
}
|
}
|
||||||
auto list = app.GetSharedMasterList();
|
auto list = app.GetSharedMasterList();
|
||||||
if (list.size() > 1 && settings.runningType == RUNNING_PARALLEL) {
|
if (list.size() > 1 && settings.runningType == RUNNING_PARALLEL) {
|
||||||
for (int i=1; i<list.size(); ++i) {
|
// 并发上线的并行实例只派生一次:主控端重启重连时会再次进入 StartClient,
|
||||||
std::string addr = list[i] + ":" + std::to_string(settings.ServerPort());
|
// 若不守护会重复派生并行连接。主实例的 SetServer(list[0]) 保持每次执行,
|
||||||
auto a = NewClientStartArg(addr.c_str(), IsSharedRunning, FALSE);
|
// 让主实例始终指向域名解析出的第一个 IP。
|
||||||
if (nullptr != a) CloseHandle(__CreateThread(0, 0, StartClientApp, a, 0, 0));
|
static bool parallelHasRun = false;
|
||||||
|
if (!parallelHasRun) {
|
||||||
|
parallelHasRun = true;
|
||||||
|
for (int i=1; i<list.size(); ++i) {
|
||||||
|
std::string addr = list[i] + ":" + std::to_string(settings.ServerPort());
|
||||||
|
auto a = NewClientStartArg(addr.c_str(), IsSharedRunning, FALSE);
|
||||||
|
if (nullptr != a) CloseHandle(__CreateThread(0, 0, StartClientApp, a, 0, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// The main ClientApp.
|
// The main ClientApp.
|
||||||
settings.SetServer(list[0].c_str(), settings.ServerPort());
|
settings.SetServer(list[0].c_str(), settings.ServerPort());
|
||||||
|
|||||||
Reference in new issue
Block a user