Simple exponential backoff and jitter function that provides the delay value for the next retry attempt. After a failure of an operation that needs to be retried, the application should use this function to obtain the backoff delay value for the next retry, and then wait for the backoff time period before retrying the operation.
- Parameters
-
[in,out] | pRetryContext | Structure containing parameters for the next backoff value calculation. |
[in] | randomValue | The random value to use for calculation of the backoff period. The random value should be in the range of [0, UINT32_MAX]. |
[out] | pNextBackOff | This will be populated with the backoff value (in milliseconds) for the next retry attempt. The value does not exceed the maximum backoff delay configured in the context. |
- Note
- For generating a random number, it is recommended to use a Random Number Generator that is seeded with a device-specific entropy source so that possibility of collisions between multiple devices retrying the network operations can be mitigated.
- Returns
- BackoffAlgorithmSuccess after a successful sleep; BackoffAlgorithmRetriesExhausted when all attempts are exhausted.
From the Code Example for backoffAlgorithm API, following is the part relevant to the BackoffAlgorithm_GetNextBackoff API.
( void ) clock_gettime( CLOCK_REALTIME, &tp );
srand( tp.tv_sec );
do
{
dnsStatus = getaddrinfo( serverAddress, NULL, &hints, pListHead );
if( dnsStatus != 0 )
{
( void ) usleep( nextRetryBackoff * 1000U );
}
BackoffAlgorithmStatus_t BackoffAlgorithm_GetNextBackoff(BackoffAlgorithmContext_t *pRetryContext, uint32_t randomValue, uint16_t *pNextBackOff)
Simple exponential backoff and jitter function that provides the delay value for the next retry attem...
Definition: backoff_algorithm.c:38
@ BackoffAlgorithmRetriesExhausted
The function exhausted all retry attempts.
Definition: backoff_algorithm.h:58