Fix: keep the in-process test client alive on compression switch

Switching wire compression used to set g_bExit = S_CLIENT_UPDATE and
disconnect. Standalone clients restart fine, but the in-process test
client (ServerDll loaded with MemoryModule) only restarts AutoRun on
S_SERVER_EXIT; S_CLIENT_UPDATE made TestRun return and AutoRun exit, so
the host went offline for good and the "Run Test Program" menu stayed
disabled.

The command handler now disconnects and calls
IOCPClient::SetWireCompression() on the existing connection object.
The reconnect loop reuses it with the new mode; sub-connections are
rebuilt from the saved config after the main link reconnects. g_bExit
is no longer touched.

The experimental menu gains two 16x16 icons (blue Z for zstd, orange L
for zlib) and grays the algorithm the selected hosts already use
(all-zstd grays ZSTD, all-zlib grays ZLIB, mixed leaves both enabled,
unsupported clients gray both). The new strings are translated in the
en_US, de_DE and zh_TW packs (the German pack also gained the missing
"Experimental" group title).

Verified: with an isolated Debug server, the in-process test client
switches zstd -> zlib -> zstd, reconnects in about 3 s each time and
keeps receiving MasterSettings; the menu reports the expected gray
state and icons in a captured screenshot.

Co-Authored-By: deepseek-flash
This commit was merged in pull request #9.
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-24 10:33:42 +01:00
1 parent 0e20e0bbdb
commit e6a3255a2b
13 files changed
+74 -17

No files matched your search

+12 -6
View File
@@ -1127,9 +1127,9 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
}
case COMMAND_SET_COMPRESS: {
// 线缆压缩切换(zstd / zlib):写本机配置后重启 StartClient 线程。
// 注意不能只断开当前连接:IOCPClient 的压缩模式在构造时读取,复用旧实例重连
// 不会重新读配置。置 S_CLIENT_UPDATE 让 StartClientApp 重建连接对象。
// 线缆压缩切换(zstd / zlib):写本机配置后只断开当前连接,复用 IOCPClient
// 原地切换 m_useZlib,由 StartClient 重连循环用新模式建链。不能置 S_CLIENT_UPDATE:
// 进程内测试客户端的 AutoRun 只在 S_SERVER_EXIT 时重启,详见下方断连处说明。
std::string mode;
if (ulLength > 1)
mode.assign((const char*)szBuffer + 1, ulLength - 1);
@@ -1146,10 +1146,16 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
}
if (m_cfg)
m_cfg->SetStr("settings", "compress", mode);
Mprintf("[compress-switch] set to %s, restarting client\n", mode.c_str());
g_bExit = S_CLIENT_UPDATE;
if (m_ClientObject)
Mprintf("[compress-switch] set to %s, reconnecting\n", mode.c_str());
// 只断开当前连接,不要置 S_CLIENT_UPDATE:进程内测试客户端(MemoryModule 加载的
// ServerDll)的 AutoRun 只在 S_SERVER_EXIT 时重启,S_CLIENT_UPDATE 会让 TestRun
// 直接返回、AutoRun 退出,客户端停死且主控的"运行测试程序"菜单永久置灰。
// 重连循环复用同一个 IOCPClient,这里先把压缩模式切过去即可;子连接在重连后
// 由新的 Manager 按配置重建。先断开再切模式,避免旧连接上还有包用新算法发出。
if (m_ClientObject) {
m_ClientObject->Disconnect();
m_ClientObject->SetWireCompression(mode == "zlib");
}
break;
}