Skip to content

Instantly share code, notes, and snippets.

@jammerxd
Created September 17, 2021 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jammerxd/f905b45d229215b3b80fbc8e445156b2 to your computer and use it in GitHub Desktop.
Save jammerxd/f905b45d229215b3b80fbc8e445156b2 to your computer and use it in GitHub Desktop.
TimedBCast method
void timedBcast(boost::system::error_code e)
{
std::chrono::high_resolution_clock::time_point tStart = std::chrono::high_resolution_clock::now();
std::chrono::high_resolution_clock::time_point tPrepared = tStart;
if (!e && !stop)
{
if (srv != nullptr)
{
if (messageCount >= 1000)
{
messageCount = 0;
}
auto msg = std::make_shared<Message<MessageTypes>>();
msg->message_header.id = MessageTypes::MessageAll;
msg->Append(std::string(rand() % 102400 + 81920, 'a') + " " + std::to_string(messageCount++));
msg->TransactionId = "Broadcast";
tPrepared = std::chrono::high_resolution_clock::now();
srv->BroadcastMessage(std::move(msg));
auto const tDone = std::chrono::high_resolution_clock::now();
auto const time = tDone - tPrepared;
auto const time2 = tDone - tStart;
if (time != previous_time && time > 2us) {
// timer += time - 6;
std::cout << "Broadcast took " << time / 1.0us << "us | "
<< time2 / 1us << "us" << std::endl;
previous_time = time;
}
auto time_expire = 30ms - time2;
if (time_expire <= 5ms) {
time_expire = 30ms;
}
// Reschedule the timer
timer.expires_from_now(time_expire);
timer.async_wait(timedBcast);
//std::cout << "BROADCAST" << std::endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment