2019-08-30 21:46:35 +02:00
|
|
|
/*
|
|
|
|
* IXExponentialBackoff.h
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "IXExponentialBackoff.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
2019-09-23 19:25:23 +02:00
|
|
|
uint32_t calculateRetryWaitMilliseconds(uint32_t retry_count,
|
|
|
|
uint32_t maxWaitBetweenReconnectionRetries)
|
2019-08-30 21:46:35 +02:00
|
|
|
{
|
2019-12-02 22:51:45 +01:00
|
|
|
uint32_t wait_time = (retry_count < 26) ? (std::pow(2, retry_count) * 100) : 0;
|
2019-08-30 21:46:35 +02:00
|
|
|
|
|
|
|
if (wait_time > maxWaitBetweenReconnectionRetries || wait_time == 0)
|
|
|
|
{
|
|
|
|
wait_time = maxWaitBetweenReconnectionRetries;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wait_time;
|
|
|
|
}
|
2019-09-23 19:25:23 +02:00
|
|
|
} // namespace ix
|