Commit afdb3abb authored by Bob Halley's avatar Bob Halley
Browse files

zero interval and epoch; rename _get() to _now(); add _nowplusinterval()

parent 0f287538
......@@ -41,6 +41,8 @@ typedef struct isc_interval {
unsigned int nanoseconds;
} isc_interval_t;
extern isc_interval_t *isc_interval_zero;
void
isc_interval_set(isc_interval_t *i,
unsigned int seconds, unsigned int nanoseconds);
......@@ -83,6 +85,8 @@ typedef struct isc_time {
unsigned int nanoseconds;
} isc_time_t;
extern isc_time_t *isc_time_epoch;
void
isc_time_settoepoch(isc_time_t *t);
/*
......@@ -106,7 +110,7 @@ isc_time_isepoch(isc_time_t *t);
*/
isc_result_t
isc_time_get(isc_time_t *t);
isc_time_now(isc_time_t *t);
/*
* Set 't' to the current absolute time.
*
......@@ -120,6 +124,28 @@ isc_time_get(isc_time_t *t);
* Unexpected error
*/
isc_result_t
isc_time_nowplusinterval(isc_time_t *t, isc_interval_t *i);
/*
* Set *t to the current absolute time + i.
*
* Note:
*
* This call is equivalent to:
*
* isc_time_now(t);
* isc_time_add(t, i, t);
*
* Requires:
*
* 't' and 'i' are valid.
*
* Returns:
*
* Success
* Unexpected error
*/
int
isc_time_compare(isc_time_t *t1, isc_time_t *t2);
/*
......
......@@ -34,6 +34,9 @@
*** Intervals
***/
static isc_interval_t zero_interval = { 0, 0 };
isc_interval_t *isc_interval_zero = &zero_interval;
void
isc_interval_set(isc_interval_t *i,
unsigned int seconds, unsigned int nanoseconds) {
......@@ -71,6 +74,9 @@ isc_interval_iszero(isc_interval_t *i) {
*** Absolute Times
***/
static isc_time_t epoch = { 0, 0 };
isc_time_t *isc_time_epoch = &epoch;
void
isc_time_settoepoch(isc_time_t *t) {
/*
......@@ -99,7 +105,7 @@ isc_time_isepoch(isc_time_t *t) {
}
isc_result_t
isc_time_get(isc_time_t *t) {
isc_time_now(isc_time_t *t) {
struct timeval tv;
/*
......@@ -119,6 +125,32 @@ isc_time_get(isc_time_t *t) {
return (ISC_R_SUCCESS);
}
isc_result_t
isc_time_nowplusinterval(isc_time_t *t, isc_interval_t *i) {
struct timeval tv;
/*
* Set *t to the current absolute time + i.
*/
REQUIRE(t != NULL);
REQUIRE(i != NULL);
if (gettimeofday(&tv, NULL) == -1) {
UNEXPECTED_ERROR(__FILE__, __LINE__, strerror(errno));
return (ISC_R_UNEXPECTED);
}
t->seconds = tv.tv_sec + i->seconds;
t->nanoseconds = tv.tv_usec * 1000 + i->nanoseconds;
if (t->nanoseconds > 1000000000) {
t->seconds++;
t->nanoseconds -= 1000000000;
}
return (ISC_R_SUCCESS);
}
int
isc_time_compare(isc_time_t *t1, isc_time_t *t2) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment