ensure a handshake goes out the first time

This commit is contained in:
Stephen Birarda 2015-09-15 09:48:17 -07:00
parent a27e0e7cc7
commit 6a186ad1fe

View file

@ -279,17 +279,13 @@ void SendQueue::run() {
if (!_hasReceivedHandshakeACK) {
// we haven't received a handshake ACK from the client
// if it has been at least 100ms since we last sent a handshake, send another now
// hold the time of last send in a static
static auto lastSendHandshake = p_high_resolution_clock::time_point().min();
static const auto HANDSHAKE_RESEND_INTERVAL_MS = std::chrono::milliseconds(100);
// calculation the duration since the last handshake send
auto sinceLastHandshake = std::chrono::duration_cast<std::chrono::milliseconds>(p_high_resolution_clock::now()
- lastSendHandshake);
// hold the time of last send in a static
static auto lastSendHandshake = p_high_resolution_clock::now() - HANDSHAKE_RESEND_INTERVAL_MS;
if (sinceLastHandshake >= HANDSHAKE_RESEND_INTERVAL_MS) {
if (p_high_resolution_clock::now() - lastSendHandshake >= HANDSHAKE_RESEND_INTERVAL_MS) {
// it has been long enough since last handshake, send another
static auto handshakePacket = ControlPacket::create(ControlPacket::Handshake, 0);
@ -299,9 +295,7 @@ void SendQueue::run() {
}
// we wait for the ACK or the re-send interval to expire
_handshakeACKCondition.wait_until(handshakeLock,
p_high_resolution_clock::now()
+ HANDSHAKE_RESEND_INTERVAL_MS);
_handshakeACKCondition.wait_until(handshakeLock, p_high_resolution_clock::now() + HANDSHAKE_RESEND_INTERVAL_MS);
// Once we're here we've either received the handshake ACK or it's going to be time to re-send a handshake.
// Either way let's continue processing - no packets will be sent if no handshake ACK has been received.