Shutdown
| 157 | |
| 158 | // Shutdown |
| 159 | void DllReaderShutdown() { |
| 160 | // Signal stop |
| 161 | if (hStopEventDll != NULL) { |
| 162 | SetEvent(hStopEventDll); |
| 163 | } |
| 164 | |
| 165 | // Unblock StartAndWaitForClient with a fake connect |
| 166 | try { |
| 167 | PipeClient pipeClient("RedEdr DllReaderShutdown"); |
| 168 | char buf[DLL_CONFIG_LEN] = { 0 }; |
| 169 | const char* s = ""; |
| 170 | |
| 171 | if (pipeClient.Connect(DLL_PIPE_NAME)) { |
| 172 | pipeClient.Receive(buf, DLL_CONFIG_LEN); |
| 173 | pipeClient.Send((char*)s); |
| 174 | pipeClient.Disconnect(); |
| 175 | } |
| 176 | } |
| 177 | catch (const std::exception& e) { |
| 178 | LOG_A(LOG_WARNING, "DllReaderShutdown: Exception during pipe cleanup: %s", e.what()); |
| 179 | } |
| 180 | catch (...) { |
| 181 | LOG_A(LOG_WARNING, "DllReaderShutdown: Unknown exception during pipe cleanup"); |
| 182 | } |
| 183 | |
| 184 | // Wait for server thread to exit (it joins client threads internally) |
| 185 | if (hDllServerThreadHandle != NULL) { |
| 186 | if (WaitForSingleObject(hDllServerThreadHandle, 5000) == WAIT_TIMEOUT) { |
| 187 | LOG_A(LOG_WARNING, "DllReader: Server thread did not exit in time, force-terminating"); |
| 188 | TerminateThread(hDllServerThreadHandle, 1); |
| 189 | } |
| 190 | CloseHandle(hDllServerThreadHandle); |
| 191 | hDllServerThreadHandle = NULL; |
| 192 | } |
| 193 | |
| 194 | if (hStopEventDll != NULL) { |
| 195 | CloseHandle(hStopEventDll); |
| 196 | hStopEventDll = NULL; |
| 197 | } |
| 198 | if (threadReadynessDll != NULL) { |
| 199 | CloseHandle(threadReadynessDll); |
| 200 | threadReadynessDll = NULL; |
| 201 | } |
| 202 | } |
| 203 |
no test coverage detected