if (isc_time_compare(&expires, &now) <= 0) {
isc_interval_set(&interval, 0, 1);
} else {
- isc_time_t tmp;
- isc_interval_set(&interval, isc_time_seconds(&now),
- isc_time_nanoseconds(&now));
- isc_time_subtract(&expires, &interval, &tmp);
- isc_interval_set(&interval, isc_time_seconds(&tmp),
- isc_time_nanoseconds(&tmp));
+ isc_time_subtract(&expires, &now, &interval);
}
return (isc_timer_reset(fctx->timer, isc_timertype_once, &interval,
if (isc_time_compare(&next, now) <= 0) {
isc_interval_set(&interval, 0, 1);
} else {
- /*
- * In theory, we could just type isc_interval_t to
- * isc_time_t and back, but there's no such guarantee,
- * so a safer method is being used here.
- */
- isc_time_t tmp;
- isc_interval_set(&interval, isc_time_seconds(now),
- isc_time_nanoseconds(now));
- isc_time_subtract(&next, &interval, &tmp);
- isc_interval_set(&interval, isc_time_seconds(&tmp),
- isc_time_nanoseconds(&tmp));
+ isc_time_subtract(&next, now, &interval);
}
result = isc_timer_reset(zone->timer, isc_timertype_once,
#include <stdbool.h>
#include <isc/lang.h>
+#include <isc/time.h>
#include <isc/types.h>
ISC_LANG_BEGINDECLS
#include <isc/lang.h>
#include <isc/types.h>
-/***
- *** Intervals
- ***/
-
-/*!
- * \brief
- * The contents of this structure are private, and MUST NOT be accessed
- * directly by callers.
- *
- * The contents are exposed only to allow callers to avoid dynamic allocation.
- */
-struct isc_interval {
- unsigned int seconds;
- unsigned int nanoseconds;
-};
-
-extern const isc_interval_t *const isc_interval_zero;
-
/*
* ISC_FORMATHTTPTIMESTAMP_SIZE needs to be 30 in C locale and potentially
* more for other locales to handle longer national abbreviations when
*/
#define ISC_FORMATHTTPTIMESTAMP_SIZE 50
+/*
+ * Semantic shims to distinguish between relative and absolute time
+ */
+#define isc_interval_zero isc_time_epoch
+#define isc_interval_t isc_time_t
+
ISC_LANG_BEGINDECLS
-void
-isc_interval_set(isc_interval_t *i, unsigned int seconds,
- unsigned int nanoseconds);
+#define isc_interval_set(i, seconds, nanoseconds) \
+ isc_time_set((isc_time_t *)i, seconds, nanoseconds)
/*%<
* Set 'i' to a value representing an interval of 'seconds' seconds and
* 'nanoseconds' nanoseconds, suitable for use in isc_time_add() and
*\li nanoseconds < 1000000000.
*/
-bool
-isc_interval_iszero(const isc_interval_t *i);
+#define isc_interval_iszero(i) isc_time_isepoch((const isc_time_t *)i)
/*%<
* Returns true iff. 'i' is the zero interval.
*
*\li 'i' is a valid pointer.
*/
-unsigned int
-isc_interval_ms(const isc_interval_t *i);
+#define isc_interval_ms(i) isc_time_miliseconds((const isc_time_t *)i)
/*%<
* Returns interval 'i' expressed as a number of milliseconds.
*
*\li The returned value is less than 1*10^9.
*/
+uint32_t
+isc_time_miliseconds(const isc_time_t *t);
+/*%<
+ * Returns time 't' expressed as a number of milliseconds.
+ *
+ * Requires:
+ *
+ *\li 't' is a valid pointer.
+ */
+
void
isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len);
/*%<
typedef void(isc_httpdondestroy_t)(void *); /*%< Callback on destroying httpd */
typedef struct isc_interface isc_interface_t; /*%< Interface */
typedef struct isc_interfaceiter isc_interfaceiter_t; /*%< Interface Iterator */
-typedef struct isc_interval isc_interval_t; /*%< Interval */
typedef struct isc_lex isc_lex_t; /*%< Lex */
typedef struct isc_log isc_log_t; /*%< Log */
typedef struct isc_logcategory isc_logcategory_t; /*%< Log Category */
#define CLOCKSOURCE_HIRES CLOCKSOURCE
#endif /* #ifndef CLOCKSOURCE_HIRES */
-/*%
- *** Intervals
- ***/
-
-#if !defined(UNIT_TESTING)
-static const isc_interval_t zero_interval = { 0, 0 };
-const isc_interval_t *const isc_interval_zero = &zero_interval;
-#endif
-
-void
-isc_interval_set(isc_interval_t *i, unsigned int seconds,
- unsigned int nanoseconds) {
- REQUIRE(i != NULL);
- REQUIRE(nanoseconds < NS_PER_S);
-
- i->seconds = seconds;
- i->nanoseconds = nanoseconds;
-}
-
-bool
-isc_interval_iszero(const isc_interval_t *i) {
- REQUIRE(i != NULL);
- INSIST(i->nanoseconds < NS_PER_S);
-
- if (i->seconds == 0 && i->nanoseconds == 0) {
- return (true);
- }
-
- return (false);
-}
-
-unsigned int
-isc_interval_ms(const isc_interval_t *i) {
- REQUIRE(i != NULL);
- INSIST(i->nanoseconds < NS_PER_S);
-
- return ((i->seconds * MS_PER_S) + (i->nanoseconds / NS_PER_MS));
-}
-
-/***
- *** Absolute Times
- ***/
-
#if !defined(UNIT_TESTING)
static const isc_time_t epoch = { 0, 0 };
const isc_time_t *const isc_time_epoch = &epoch;
static inline isc_result_t
time_now(isc_time_t *t, clockid_t clock) {
struct timespec ts;
- char strbuf[ISC_STRERRORSIZE];
REQUIRE(t != NULL);
if (clock_gettime(clock, &ts) == -1) {
+ char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__, "%s", strbuf);
return (ISC_R_UNEXPECTED);
isc_result_t
isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
struct timespec ts;
- char strbuf[ISC_STRERRORSIZE];
REQUIRE(t != NULL);
REQUIRE(i != NULL);
INSIST(i->nanoseconds < NS_PER_S);
if (clock_gettime(CLOCKSOURCE, &ts) == -1) {
+ char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__, "%s", strbuf);
return (ISC_R_UNEXPECTED);
return ((uint32_t)t->nanoseconds);
}
+uint32_t
+isc_time_miliseconds(const isc_time_t *t) {
+ REQUIRE(t != NULL);
+ INSIST(t->nanoseconds < NS_PER_S);
+
+ return ((t->seconds * MS_PER_S) + (t->nanoseconds / NS_PER_MS));
+}
+
void
isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len) {
time_t now;