-
-
Save jammerxd/f905b45d229215b3b80fbc8e445156b2 to your computer and use it in GitHub Desktop.
TimedBCast method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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