Pipe Reader Thread: Server
| 61 | |
| 62 | // Pipe Reader Thread: Server |
| 63 | DWORD WINAPI DllReaderThread(LPVOID param) { |
| 64 | LOG_A(LOG_DEBUG, "!DllReader Thread: begin"); |
| 65 | |
| 66 | // Loop which accepts new clients |
| 67 | while (WaitForSingleObject(hStopEventDll, 0) != WAIT_OBJECT_0) { |
| 68 | std::unique_ptr<PipeServer> pipeServer = std::make_unique<PipeServer>("DllReader", (wchar_t*) DLL_PIPE_NAME); |
| 69 | if (!pipeServer) { |
| 70 | LOG_A(LOG_ERROR, "DllReader: Failed to create PipeServer"); |
| 71 | Sleep(1000); // Brief delay before retry |
| 72 | continue; |
| 73 | } |
| 74 | |
| 75 | SetEvent(threadReadynessDll); |
| 76 | |
| 77 | if (!pipeServer->StartAndWaitForClient(TRUE)) { |
| 78 | LOG_A(LOG_ERROR, "DllReader: Failed to start pipe server or wait for client"); |
| 79 | pipeServer->Shutdown(); |
| 80 | Sleep(1000); // Brief delay before retry |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | LOG_A(LOG_INFO, "DllReader: Client connected (handle in new thread)"); |
| 85 | try { |
| 86 | // Transfer ownership to the thread |
| 87 | PipeServer* rawPtr = pipeServer.release(); |
| 88 | ConnectedDllReaderThreads.push_back(std::thread(DllReaderClientThread, rawPtr)); |
| 89 | } |
| 90 | catch (const std::exception& e) { |
| 91 | LOG_A(LOG_ERROR, "DllReader: Failed to create client thread: %s", e.what()); |
| 92 | pipeServer->Shutdown(); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // Wait for all client threads to exit |
| 97 | for (auto& t : ConnectedDllReaderThreads) { |
| 98 | if (t.joinable()) { |
| 99 | t.join(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | LOG_A(LOG_DEBUG, "!DllReader Thread: end"); |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | // Pipe Reader Thread: Process Client |
nothing calls this directly
no test coverage detected