Skip to content

Commit

Permalink
fix: add cpp retry
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonAura authored May 8, 2024
1 parent 797a835 commit ba6823e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions CAPI/cpp/API/src/Communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,18 @@ bool Communication::Recycle(int32_t playerID, int32_t teamID)

bool Communication::TryConnection(int32_t playerID, int32_t teamID)
{
protobuf::BoolRes reply;
ClientContext context;
constexpr int maxRetryNum = 10;
auto request = THUAI72Proto::THUAI72ProtobufIDMsg(playerID, teamID);
auto status = THUAI7Stub->TryConnection(&context, request, &reply);
if (status.ok())
return true;
else
return false;
for (int retryNum = 0; retryNum < maxRetryNum; retryNum++)
{
protobuf::BoolRes reply;
ClientContext context;
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
auto status = THUAI7Stub->TryConnection(&context, request, &reply);
if (status.ok())
return true;
}
return false;
}

void Communication::AddPlayer(int32_t playerID, int32_t teamID, THUAI7::ShipType ShipType)
Expand Down Expand Up @@ -274,4 +278,4 @@ protobuf::MessageToClient Communication::GetMessage2Client()
{ return haveNewMessage; });
haveNewMessage = false;
return message2Client;
}
}

0 comments on commit ba6823e

Please sign in to comment.