Skip to content

File syn_backoff.h

File List > src > syntropic > util > syn_backoff.h

Go to the documentation of this file

#ifndef SYN_BACKOFF_H
#define SYN_BACKOFF_H

#include "../common/syn_defs.h"

#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
    uint32_t min_ms;      
    uint32_t max_ms;      
    uint32_t current_ms;  
    uint8_t attempts;     
    uint8_t max_attempts; 
    uint8_t factor;       
} SYN_Backoff;

void syn_backoff_init(SYN_Backoff *b, uint32_t min_ms, uint32_t max_ms, uint8_t factor,
                      uint8_t max_attempts);

uint32_t syn_backoff_next_ms(SYN_Backoff *b);

bool syn_backoff_exhausted(const SYN_Backoff *b);

void syn_backoff_reset(SYN_Backoff *b);

#ifdef __cplusplus
}
#endif

#endif /* SYN_BACKOFF_H */