+6026. [cleanup] Deduplicate time unit conversion factors.
+ [GL !7033]
+
6025. [bug] Copy TLS identifier when setting up primaries for
catalog member zones. [GL #3638]
#include <isc/sockaddr.h>
#include <isc/string.h>
#include <isc/task.h>
+#include <isc/time.h>
#include <isc/util.h>
#include <dns/byaddr.h>
#define UDPTIMEOUT 5
#define MAXTRIES 0xffffffff
-#define NS_PER_US 1000 /*%< Nanoseconds per microsecond. */
-#define US_PER_SEC 1000000 /*%< Microseconds per second. */
-#define US_PER_MS 1000 /*%< Microseconds per millisecond. */
-
static isc_mem_t *mctx = NULL;
static isc_task_t *global_task = NULL;
static isc_loopmgr_t *loopmgr = NULL;
#include <isc/string.h>
#include <isc/task.h>
#include <isc/tid.h>
+#include <isc/time.h>
#include <isc/timer.h>
#include <isc/util.h>
#define fctx_addref(f) fctx_attach((f), &(fetchctx_t *){ NULL })
#define fctx_unref(f) fctx_detach(&(fetchctx_t *){ (f) })
-#define US_PER_SEC 1000000U
-#define US_PER_MSEC 1000U
-#define NS_PER_US 1000U
/*
* The maximum time we will wait for a single query.
*/
#define MAX_SINGLE_QUERY_TIMEOUT 9000U
-#define MAX_SINGLE_QUERY_TIMEOUT_US (MAX_SINGLE_QUERY_TIMEOUT * US_PER_MSEC)
+#define MAX_SINGLE_QUERY_TIMEOUT_US (MAX_SINGLE_QUERY_TIMEOUT * US_PER_MS)
/*
* We need to allow a individual query time to complete / timeout.
&query->start);
factor = DNS_ADB_RTTADJDEFAULT;
- rttms = rtt / US_PER_MSEC;
+ rttms = rtt / US_PER_MS;
if (rttms < DNS_RESOLVER_QRYRTTCLASS0) {
inc_stats(fctx->res,
dns_resstatscounter_queryrtt0);
*/
isc_time_now(&now);
limit = isc_time_microdiff(&fctx->expires, &now);
- if (limit < US_PER_MSEC) {
+ if (limit < US_PER_MS) {
FCTXTRACE("fetch already expired");
isc_interval_set(&fctx->interval, 0, 0);
return;
}
- us = fctx->res->retryinterval * US_PER_MSEC;
+ us = fctx->res->retryinterval * US_PER_MS;
/*
* Exponential backoff after the first few tries.
if ((fctx->options & DNS_FETCHOPT_TRYSTALE_ONTIMEOUT) != 0) {
uint64_t stale = isc_time_microdiff(&fctx->expires_try_stale,
&now);
- if (stale >= US_PER_MSEC && us > stale) {
+ if (stale >= US_PER_MS && us > stale) {
FCTXTRACE("setting stale timeout");
us = stale;
}
*/
isc_time_now(&now);
timeleft = isc_time_microdiff(&fctx->expires_try_stale, &now);
- if (timeleft >= US_PER_MSEC) {
+ if (timeleft >= US_PER_MS) {
return (ISC_R_SUCCESS);
}
* resume waiting.
*/
timeleft = isc_time_microdiff(&fctx->next_timeout, &now);
- if (timeleft >= US_PER_MSEC) {
- dns_dispatch_resume(query->dispentry, (timeleft / US_PER_MSEC));
+ if (timeleft >= US_PER_MS) {
+ dns_dispatch_resume(query->dispentry, (timeleft / US_PER_MS));
return (ISC_R_COMPLETE);
}
isc_time_now(&now);
/* netmgr timeouts are accurate to the millisecond */
- if (isc_time_microdiff(&fctx->expires, &now) < US_PER_MSEC) {
+ if (isc_time_microdiff(&fctx->expires, &now) < US_PER_MS) {
FCTXTRACE("stopped trying to make fetch happen");
} else {
FCTXTRACE("query timed out; no response");
#include <isc/lang.h>
#include <isc/types.h>
+enum {
+ MS_PER_SEC = 1000, /*%< Milliseonds per second. */
+ US_PER_MS = 1000, /*%< Microseconds per millisecond. */
+ US_PER_SEC = 1000 * 1000, /*%< Microseconds per second. */
+ NS_PER_US = 1000, /*%< Nanoseconds per millisecond. */
+ NS_PER_MS = 1000 * 1000, /*%< Nanoseconds per microsecond. */
+ NS_PER_SEC = 1000 * 1000 * 1000, /*%< Nanoseconds per second. */
+};
+
/*
* ISC_FORMATHTTPTIMESTAMP_SIZE needs to be 30 in C locale and potentially
* more for other locales to handle longer national abbreviations when
#include <isc/stdtime.h>
#include <isc/strerr.h>
+#include <isc/time.h>
#include <isc/util.h>
-#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */
-
#if defined(CLOCK_REALTIME_COARSE)
#define CLOCKSOURCE CLOCK_REALTIME_COARSE
#elif defined(CLOCK_REALTIME_FAST)
FATAL_SYSERROR(errno, "clock_gettime()");
}
- REQUIRE(ts.tv_sec > 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_S);
+ REQUIRE(ts.tv_sec > 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_SEC);
*t = (isc_stdtime_t)ts.tv_sec;
}
#include <isc/tm.h>
#include <isc/util.h>
-#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */
-#define NS_PER_US 1000 /*%< Nanoseconds per microsecond. */
-#define NS_PER_MS 1000000 /*%< Nanoseconds per millisecond. */
-#define MS_PER_S 1000 /*%< Milliseonds per second. */
-
#if defined(CLOCK_REALTIME)
#define CLOCKSOURCE_HIRES CLOCK_REALTIME
#endif /* #if defined(CLOCK_REALTIME) */
void
isc_time_set(isc_time_t *t, unsigned int seconds, unsigned int nanoseconds) {
REQUIRE(t != NULL);
- REQUIRE(nanoseconds < NS_PER_S);
+ REQUIRE(nanoseconds < NS_PER_SEC);
t->seconds = seconds;
t->nanoseconds = nanoseconds;
bool
isc_time_isepoch(const isc_time_t *t) {
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
if (t->seconds == 0 && t->nanoseconds == 0) {
return (true);
return (ISC_R_UNEXPECTED);
}
- if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= NS_PER_S) {
+ if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= NS_PER_SEC) {
return (ISC_R_UNEXPECTED);
}
REQUIRE(t != NULL);
REQUIRE(i != NULL);
- INSIST(i->nanoseconds < NS_PER_S);
+ INSIST(i->nanoseconds < NS_PER_SEC);
if (clock_gettime(CLOCKSOURCE, &ts) == -1) {
UNEXPECTED_SYSERROR(errno, "clock_gettime()");
return (ISC_R_UNEXPECTED);
}
- if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= NS_PER_S) {
+ if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= NS_PER_SEC) {
return (ISC_R_UNEXPECTED);
}
t->seconds = ts.tv_sec + i->seconds;
t->nanoseconds = ts.tv_nsec + i->nanoseconds;
- if (t->nanoseconds >= NS_PER_S) {
+ if (t->nanoseconds >= NS_PER_SEC) {
t->seconds++;
- t->nanoseconds -= NS_PER_S;
+ t->nanoseconds -= NS_PER_SEC;
}
return (ISC_R_SUCCESS);
int
isc_time_compare(const isc_time_t *t1, const isc_time_t *t2) {
REQUIRE(t1 != NULL && t2 != NULL);
- INSIST(t1->nanoseconds < NS_PER_S && t2->nanoseconds < NS_PER_S);
+ INSIST(t1->nanoseconds < NS_PER_SEC && t2->nanoseconds < NS_PER_SEC);
if (t1->seconds < t2->seconds) {
return (-1);
isc_result_t
isc_time_add(const isc_time_t *t, const isc_interval_t *i, isc_time_t *result) {
REQUIRE(t != NULL && i != NULL && result != NULL);
- REQUIRE(t->nanoseconds < NS_PER_S && i->nanoseconds < NS_PER_S);
+ REQUIRE(t->nanoseconds < NS_PER_SEC && i->nanoseconds < NS_PER_SEC);
/* Seconds */
#if HAVE_BUILTIN_ADD_OVERFLOW
/* Nanoseconds */
result->nanoseconds = t->nanoseconds + i->nanoseconds;
- if (result->nanoseconds >= NS_PER_S) {
+ if (result->nanoseconds >= NS_PER_SEC) {
if (result->seconds == UINT_MAX) {
return (ISC_R_RANGE);
}
- result->nanoseconds -= NS_PER_S;
+ result->nanoseconds -= NS_PER_SEC;
result->seconds++;
}
isc_time_subtract(const isc_time_t *t, const isc_interval_t *i,
isc_time_t *result) {
REQUIRE(t != NULL && i != NULL && result != NULL);
- REQUIRE(t->nanoseconds < NS_PER_S && i->nanoseconds < NS_PER_S);
+ REQUIRE(t->nanoseconds < NS_PER_SEC && i->nanoseconds < NS_PER_SEC);
/* Seconds */
#if HAVE_BUILTIN_SUB_OVERFLOW
return (ISC_R_RANGE);
}
result->seconds--;
- result->nanoseconds = NS_PER_S + t->nanoseconds -
+ result->nanoseconds = NS_PER_SEC + t->nanoseconds -
i->nanoseconds;
}
uint64_t i1, i2, i3;
REQUIRE(t1 != NULL && t2 != NULL);
- INSIST(t1->nanoseconds < NS_PER_S && t2->nanoseconds < NS_PER_S);
+ INSIST(t1->nanoseconds < NS_PER_SEC && t2->nanoseconds < NS_PER_SEC);
- i1 = (uint64_t)t1->seconds * NS_PER_S + t1->nanoseconds;
- i2 = (uint64_t)t2->seconds * NS_PER_S + t2->nanoseconds;
+ i1 = (uint64_t)t1->seconds * NS_PER_SEC + t1->nanoseconds;
+ i2 = (uint64_t)t2->seconds * NS_PER_SEC + t2->nanoseconds;
if (i1 <= i2) {
return (0);
uint32_t
isc_time_seconds(const isc_time_t *t) {
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
return ((uint32_t)t->seconds);
}
time_t seconds;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
/*
* Ensure that the number of seconds represented by t->seconds
isc_time_nanoseconds(const isc_time_t *t) {
REQUIRE(t != NULL);
- ENSURE(t->nanoseconds < NS_PER_S);
+ ENSURE(t->nanoseconds < NS_PER_SEC);
return ((uint32_t)t->nanoseconds);
}
uint32_t
isc_time_miliseconds(const isc_time_t *t) {
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
- return ((t->seconds * MS_PER_S) + (t->nanoseconds / NS_PER_MS));
+ return ((t->seconds * MS_PER_SEC) + (t->nanoseconds / NS_PER_MS));
}
void
struct tm tm;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
struct tm tm;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
struct tm tm;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
struct tm tm;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
struct tm tm;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
struct tm tm;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
struct tm tm;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
struct tm tm;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
struct tm tm;
REQUIRE(t != NULL);
- INSIST(t->nanoseconds < NS_PER_S);
+ INSIST(t->nanoseconds < NS_PER_SEC);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
#include <isc/loop.h>
#include <isc/ratelimiter.h>
#include <isc/task.h>
+#include <isc/time.h>
#include "ratelimiter.c"
#include <tests/isc.h>
-#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */
-
isc_ratelimiter_t *rl = NULL;
ISC_LOOP_TEST_IMPL(ratelimiter_create) {
isc_event_t *event = NULL;
isc_interval_t interval;
- isc_interval_set(&interval, 1, NS_PER_S / 10);
+ isc_interval_set(&interval, 1, NS_PER_SEC / 10);
expect_assert_failure(isc_ratelimiter_setinterval(NULL, &interval));
expect_assert_failure(isc_ratelimiter_setinterval(rl, NULL));
isc_event_t *event = NULL;
isc_interval_t interval;
- isc_interval_set(&interval, 1, NS_PER_S / 10);
+ isc_interval_set(&interval, 1, NS_PER_SEC / 10);
isc_ratelimiter_setinterval(rl, &interval);
isc_ratelimiter_setpertic(rl, 2);
#include <tests/isc.h>
-#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */
-#define MAX_NS (NS_PER_S - 1)
+#define MAX_NS (NS_PER_SEC - 1)
struct time_vectors {
isc_time_t a;
const struct time_vectors vectors_add[8] = {
{ { 0, 0 }, { 0, 0 }, { 0, 0 }, ISC_R_SUCCESS },
{ { 0, MAX_NS }, { 0, MAX_NS }, { 1, MAX_NS - 1 }, ISC_R_SUCCESS },
- { { 0, NS_PER_S / 2 }, { 0, NS_PER_S / 2 }, { 1, 0 }, ISC_R_SUCCESS },
+ { { 0, NS_PER_SEC / 2 },
+ { 0, NS_PER_SEC / 2 },
+ { 1, 0 },
+ ISC_R_SUCCESS },
{ { UINT_MAX, MAX_NS }, { 0, 0 }, { UINT_MAX, MAX_NS }, ISC_R_SUCCESS },
{ { UINT_MAX, 0 }, { 0, MAX_NS }, { UINT_MAX, MAX_NS }, ISC_R_SUCCESS },
{ { UINT_MAX, 0 }, { 1, 0 }, { 0, 0 }, ISC_R_RANGE },
{ { UINT_MAX, MAX_NS }, { 0, 1 }, { 0, 0 }, ISC_R_RANGE },
- { { UINT_MAX / 2 + 1, NS_PER_S / 2 },
- { UINT_MAX / 2, NS_PER_S / 2 },
+ { { UINT_MAX / 2 + 1, NS_PER_SEC / 2 },
+ { UINT_MAX / 2, NS_PER_SEC / 2 },
{ 0, 0 },
ISC_R_RANGE },
};
const struct time_vectors vectors_sub[7] = {
{ { 0, 0 }, { 0, 0 }, { 0, 0 }, ISC_R_SUCCESS },
{ { 1, 0 }, { 0, MAX_NS }, { 0, 1 }, ISC_R_SUCCESS },
- { { 1, NS_PER_S / 2 },
+ { { 1, NS_PER_SEC / 2 },
{ 0, MAX_NS },
- { 0, NS_PER_S / 2 + 1 },
+ { 0, NS_PER_SEC / 2 + 1 },
ISC_R_SUCCESS },
{ { UINT_MAX, MAX_NS }, { UINT_MAX, 0 }, { 0, MAX_NS }, ISC_R_SUCCESS },
{ { 0, 0 }, { 1, 0 }, { 0, 0 }, ISC_R_RANGE },
isc_interval_t timer_interval;
isc_timertype_t timer_type;
-#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */
ISC_LOOP_TEARDOWN_IMPL(timer_expect) {
uint64_t diff = (timer_stop - timer_start) / 1000000000;
assert_true(diff == timer_expect);
teardown_loop_timer_expect) {
isc_timer_create(mainloop, timer_event, NULL, &timer);
- isc_interval_set(&timer_interval, 0, NS_PER_S / 2);
+ isc_interval_set(&timer_interval, 0, NS_PER_SEC / 2);
isc_timer_start(timer, timer_type, &timer_interval);
}
isc_timer_start(timer, timer_type, &timer_interval);
/* Then fire every 1/4 second */
- isc_interval_set(&timer_interval, 0, NS_PER_S / 4);
+ isc_interval_set(&timer_interval, 0, NS_PER_SEC / 4);
}
ISC_TEST_LIST_START