From 115fcec8e5aa1c6d61527e1cd23b7b5fd952366e Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 29 Apr 2019 10:45:45 +0100 Subject: [PATCH] Close crash handling server if no client connects in 5 seconds --- renderdoccmd/renderdoccmd_win32.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/renderdoccmd/renderdoccmd_win32.cpp b/renderdoccmd/renderdoccmd_win32.cpp index 905eb2e01..a86369fe6 100644 --- a/renderdoccmd/renderdoccmd_win32.cpp +++ b/renderdoccmd/renderdoccmd_win32.cpp @@ -81,11 +81,17 @@ HINSTANCE hInstance = NULL; using google_breakpad::ClientInfo; using google_breakpad::CrashGenerationServer; +bool clientConnected = false; bool exitServer = false; wstring wdump = L""; std::vector customInfo; +static void _cdecl OnClientConnected(void *context, const ClientInfo *client_info) +{ + clientConnected = true; +} + static void _cdecl OnClientCrashed(void *context, const ClientInfo *client_info, const wstring *dump_path) { @@ -452,15 +458,14 @@ struct CrashHandlerCommand : public Command wchar_t tempPath[MAX_PATH] = {0}; GetTempPathW(MAX_PATH - 1, tempPath); - Sleep(100); - wstring dumpFolder = tempPath; dumpFolder += L"RenderDoc/dumps"; CreateDirectoryW(dumpFolder.c_str(), NULL); - crashServer = new CrashGenerationServer(pipe.c_str(), NULL, NULL, NULL, OnClientCrashed, NULL, - OnClientExited, NULL, NULL, NULL, true, &dumpFolder); + crashServer = + new CrashGenerationServer(pipe.c_str(), NULL, OnClientConnected, NULL, OnClientCrashed, + NULL, OnClientExited, NULL, NULL, NULL, true, &dumpFolder); if(!crashServer->Start()) { @@ -478,6 +483,9 @@ struct CrashHandlerCommand : public Command CloseHandle(readyEvent); } + const int loopSleep = 100; + int elapsedTime = 0; + MSG msg; ZeroMemory(&msg, sizeof(msg)); while(!exitServer) @@ -494,7 +502,12 @@ struct CrashHandlerCommand : public Command if(msg.message == WM_QUIT) break; - Sleep(100); + Sleep(loopSleep); + elapsedTime += loopSleep; + + // break out of the loop if + if(elapsedTime > 5000 && !clientConnected) + break; } delete crashServer;