Skip to content

Commit 1866e33

Browse files
committed
[WASimClient] Improve handling of SimConnect connection abort while still waiting for a response.
1 parent 5f586d4 commit 1866e33

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/WASimClient/WASimClient.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ class WASimClient::Private
583583
return E_TIMEOUT;
584584
}
585585

586+
// bail out if connection was canceled while waiting
587+
if (!runDispatchLoop)
588+
return E_FAIL;
589+
586590
// register server's Connect command event, exit on failure
587591
if FAILED(hr = SimConnectHelper::newClientEvent(hSim, CLI_EVENT_CONNECT, EVENT_NAME_CONNECT)) {
588592
disconnectSimulator();
@@ -638,12 +642,15 @@ class WASimClient::Private
638642
LOG_DBG << "Shutting down...";
639643
disconnectServer(!onQuitEvent);
640644
setStatus(ClientStatus::ShuttingDown);
641-
SetEvent(hDispatchStopEvent); // signal thread to exit
642-
//d->dispatchThread.join();
643645

644-
// check for dispatch loop thread shutdown (this is really just for logging/debug purposes)
645-
if (!waitCondition([&]() { return !runDispatchLoop; }, DISPATCH_LOOP_WAIT_TIME + 100))
646-
LOG_CRT << "Dispatch loop thread still running!";
646+
if (!!hDispatchStopEvent) {
647+
SetEvent(hDispatchStopEvent); // signal thread to exit
648+
//d->dispatchThread.join();
649+
650+
// check for dispatch loop thread shutdown (this is really just for logging/debug purposes)
651+
if (!waitCondition([&]() { return !runDispatchLoop; }, DISPATCH_LOOP_WAIT_TIME + 100))
652+
LOG_CRT << "Dispatch loop thread still running!";
653+
}
647654

648655
// reset flags/counters
649656
simConnected = false;

0 commit comments

Comments
 (0)