diff options
Diffstat (limited to 'usr.bin/dig/lib/isc/unix')
| -rw-r--r-- | usr.bin/dig/lib/isc/unix/Makefile.inc | 4 | ||||
| -rw-r--r-- | usr.bin/dig/lib/isc/unix/app.c | 14 | ||||
| -rw-r--r-- | usr.bin/dig/lib/isc/unix/include/isc/time.h | 43 | ||||
| -rw-r--r-- | usr.bin/dig/lib/isc/unix/time.c | 41 |
4 files changed, 8 insertions, 94 deletions
diff --git a/usr.bin/dig/lib/isc/unix/Makefile.inc b/usr.bin/dig/lib/isc/unix/Makefile.inc index 4ef52df973a..69c3c7f18bc 100644 --- a/usr.bin/dig/lib/isc/unix/Makefile.inc +++ b/usr.bin/dig/lib/isc/unix/Makefile.inc @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile.inc,v 1.5 2020/02/17 19:45:00 jung Exp $ +# $OpenBSD: Makefile.inc,v 1.6 2020/09/14 08:37:09 florian Exp $ .PATH: ${.CURDIR}/lib/isc/unix -SRCS+= app.c errno2result.c socket.c net.c time.c +SRCS+= app.c errno2result.c socket.c net.c diff --git a/usr.bin/dig/lib/isc/unix/app.c b/usr.bin/dig/lib/isc/unix/app.c index f6705f3bb9c..62535523261 100644 --- a/usr.bin/dig/lib/isc/unix/app.c +++ b/usr.bin/dig/lib/isc/unix/app.c @@ -28,7 +28,6 @@ #include <string.h> #include <isc/task.h> -#include <isc/time.h> #include <isc/util.h> /*% @@ -145,7 +144,7 @@ evloop(isc_appctx_t *ctx) { while (!ctx->want_shutdown) { int n; - struct timespec when, now; + struct timespec when, now, diff, zero ={0, 0}; struct timeval tv, *tvp; isc_socketwait_t *swait; isc_boolean_t readytasks; @@ -162,14 +161,13 @@ evloop(isc_appctx_t *ctx) { if (result != ISC_R_SUCCESS) tvp = NULL; else { - uint64_t us; - clock_gettime(CLOCK_MONOTONIC, &now); - us = isc_time_microdiff(&when, &now); - if (us == 0) + timespecsub(&when, &now, &diff); + if (timespeccmp(&diff, &zero, <=)) { call_timer_dispatch = ISC_TRUE; - tv.tv_sec = us / 1000000; - tv.tv_usec = us % 1000000; + memset(&tv, 0, sizeof(tv)); + } else + TIMESPEC_TO_TIMEVAL(&tv, &diff); tvp = &tv; } } diff --git a/usr.bin/dig/lib/isc/unix/include/isc/time.h b/usr.bin/dig/lib/isc/unix/include/isc/time.h deleted file mode 100644 index 5d294edfe60..00000000000 --- a/usr.bin/dig/lib/isc/unix/include/isc/time.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: time.h,v 1.15 2020/02/16 21:11:31 florian Exp $ */ - -#ifndef ISC_TIME_H -#define ISC_TIME_H 1 - -/*! \file */ - -#include <sys/time.h> - -#include <inttypes.h> -#include <time.h> - -uint64_t -isc_time_microdiff(const struct timespec *t1, const struct timespec *t2); -/*%< - * Find the difference in microseconds between time t1 and time t2. - * t2 is the subtrahend of t1; ie, difference = t1 - t2. - * - * Requires: - * - *\li 't1' and 't2' are valid pointers. - * - * Returns: - *\li The difference of t1 - t2, or 0 if t1 <= t2. - */ - -#endif /* ISC_TIME_H */ diff --git a/usr.bin/dig/lib/isc/unix/time.c b/usr.bin/dig/lib/isc/unix/time.c deleted file mode 100644 index d073515bfbd..00000000000 --- a/usr.bin/dig/lib/isc/unix/time.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: time.c,v 1.18 2020/02/16 21:11:31 florian Exp $ */ - -/*! \file */ - -#include <sys/time.h> -#include <time.h> - -#include <isc/time.h> -#include <isc/util.h> - -#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */ -#define NS_PER_US 1000 /*%< Nanoseconds per microsecond. */ - -uint64_t -isc_time_microdiff(const struct timespec *t1, const struct timespec *t2) { - struct timespec res; - - REQUIRE(t1 != NULL && t2 != NULL); - - timespecsub(t1, t2, &res); - if (res.tv_sec < 0) - return 0; - - return ((res.tv_sec * NS_PER_S + res.tv_nsec) / NS_PER_US); -} |
