Feature: add client log dialog with auto-refresh, icon and menu bitmap
- CClientLogManager: push thread sends incremental logs every 3s; join() instead of detach() prevents use-after-free on shutdown - CClientLog::OnReceiveComplete: handles TOKEN_REPORT_LOG on IOCP thread via PostMessage, fixing incremental packets being silently dropped - Dialog icon (ClientLog.ico) and menu bitmap (ClientLog.bmp) added; OnInitDialog loads icon; IDR_MENU_LIST_ONLINE "运行日志" item gets the bitmap Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
44
client/ClientLogManager.cpp
Normal file
44
client/ClientLogManager.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "stdafx.h"
|
||||
#include "ClientLogManager.h"
|
||||
#include "../common/commands.h"
|
||||
#include "../common/logger.h"
|
||||
|
||||
CClientLogManager::CClientLogManager(IOCPClient* ClientObject, int n, void* p)
|
||||
: CManager(ClientObject, n, p)
|
||||
, m_sentIdx(0)
|
||||
, m_running(true)
|
||||
{
|
||||
SendLogDump();
|
||||
m_pushThread = std::thread([this]() {
|
||||
while (m_running && m_ClientObject->IsConnected()) {
|
||||
for (int i = 0; i < 30 && m_running; ++i)
|
||||
Sleep(100);
|
||||
if (m_running && m_ClientObject->IsConnected())
|
||||
SendLogDump();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
CClientLogManager::~CClientLogManager()
|
||||
{
|
||||
m_running = false;
|
||||
if (m_pushThread.joinable())
|
||||
m_pushThread.join();
|
||||
}
|
||||
|
||||
VOID CClientLogManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
if (ulLength >= 1 && szBuffer[0] == COMMAND_QUERY_LOG)
|
||||
SendLogDump();
|
||||
}
|
||||
|
||||
void CClientLogManager::SendLogDump()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_sendMutex);
|
||||
std::string logs = Logger::getInstance().DumpMemoryLogFrom(m_sentIdx);
|
||||
std::vector<BYTE> pkt(1 + logs.size());
|
||||
pkt[0] = TOKEN_REPORT_LOG;
|
||||
if (!logs.empty())
|
||||
memcpy(pkt.data() + 1, logs.data(), logs.size());
|
||||
Send(pkt.data(), (UINT)pkt.size());
|
||||
}
|
||||
Reference in New Issue
Block a user