FreeBSD/contrib/ntp/libntp/ntp_intres.c
/*
 * manage_dns_retry_interval is a helper used by
 * getaddrinfo_sometime_complete and getnameinfo_sometime_complete
 * to calculate the new retry interval and schedule the next query.
 */
manage_dns_retry_interval is a helper used by
getaddrinfo_sometime_complete and getnameinfo_sometime_complete
to calculate the new retry interval and schedule the next query.
manage_dns_retry_interval is a helper used by getaddrinfo_sometime_complete and getnameinfo_sometime_complete to calculate the new retry interval and schedule the next query .
static void
manage_dns_retry_interval(
	time_t *	pscheduled,
	time_t *	pwhen,
	int *		pretry,
	time_t *	pnext_timeslot,
	int		forever
	)
{
	time_t	now;
	time_t	when;
	int	retry;
	int	retmax;
	now = time(NULL);
	retry = *pretry;
	when = max(now + retry, *pnext_timeslot);
	*pnext_timeslot = when;
	retmax = forever ? 1024 : 64;
	retry <<= 1;
	if (retry & (retry - 1))
		retry &= (retry - 1);
	else
		retry -= (retry >> 2);
	retry = min(retmax, retry);
	*pscheduled = now;
	*pwhen = when;
	*pretry = retry;
}
static void manage_dns_retry_interval ( time_t * pscheduled , time_t * pwhen , int * pretry , time_t * pnext_timeslot , int forever ) { time_t now ; time_t when ; int retry ; int retmax ; now = time ( NULL ) ; retry = * pretry ; when = max ( now + retry , * pnext_timeslot ) ; * pnext_timeslot = when ; retmax = forever ? 1024 : 64 ; retry <<= 1 ; if ( retry & ( retry - 1 ) ) retry &= ( retry - 1 ) ; else retry -= ( retry >> 2 ) ; retry = min ( retmax , retry ) ; * pscheduled = now ; * pwhen = when ; * pretry = retry ; }
manage_dns_retry_interval is a helper used by
 getaddrinfo_sometime_complete and getnameinfo_sometime_complete
 to calculate the new retry interval and schedule the next query.
manage_dns_retry_interval is a helper used by getaddrinfo_sometime_complete and getnameinfo_sometime_complete to calculate the new retry interval and schedule the next query .
/* this exponential backoff is slower than doubling up: The
	 * sequence goes 2-3-4-6-8-12-16-24-32... and the upper limit is
	 * 64 seconds for things that should not repeat forever, and
	 * 1024 when repeated forever.
	 */