Skip to content

Commit

Permalink
[WASimClient] Fixed bug introduced in 61c4cfe that prevented Client f…
Browse files Browse the repository at this point in the history
…rom completing connection to Server on first attempt.
  • Loading branch information
mpaperno committed Jul 13, 2022
1 parent b6b50a4 commit 7d10507
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/WASimClient/WASimClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,23 +665,13 @@ class WASimClient::Private
}
// The connection response, if any, is written by the server into the "command response" client data area, CLI_DATA_ID_RESPONSE, processed in SIMCONNECT_RECV_ID_CLIENT_DATA

shared_ptr<condition_variable_any> cv = make_shared<condition_variable_any>();
Command response;
TrackedResponse *tr = enqueueTrackedResponse(clientId, weak_ptr(cv));
hr = waitCommandResponse(tr->token, &response, timeout);

if (hr == E_TIMEOUT) {
LOG_ERR << "Connection request timed out after " << timeout << "ms.";
// wait until server connects or times out or disconnectSimulator() is called.
if (!waitCondition([&]() { return !runDispatchLoop || serverConnected; }, timeout)) {
LOG_ERR << "Server connection timed out or refused after " << timeout << "ms.";
setStatus(ClientStatus::SimConnected);
return E_TIMEOUT;
}
if (response.commandId != CommandId::Ack || !serverConnected) {
LOG_WRN << "Server refused connection! Reason, if any: " << quoted(response.sData);
setStatus(ClientStatus::SimConnected);
return E_FAIL;
}

serverVersion = (uint32_t)response.fData;
LOG_INF << "Connected to " WSMCMND_PROJECT_NAME " server v" << STREAM_HEX8(serverVersion);
if (serverVersion != WSMCMND_VERSION)
LOG_WRN << "Server version does not match WASimClient version " << STREAM_HEX8(WSMCMND_VERSION);
Expand Down Expand Up @@ -1280,6 +1270,8 @@ class WASimClient::Private
// Connected response
case CommandId::Connect:
serverConnected = cmd->commandId == CommandId::Ack && cmd->token == clientId;
serverVersion = (uint32_t)cmd->fData;
checkTracking = false;
break;
default:
break;
Expand Down

0 comments on commit 7d10507

Please sign in to comment.