summaryrefslogtreecommitdiff
path: root/ares__timeval.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2008-07-02 03:04:56 +0000
committerYang Tse <yangsita@gmail.com>2008-07-02 03:04:56 +0000
commitcd1f1d080c6eb417c51ba8709df430d74c2aed58 (patch)
tree0eb974860dff792b6486d4795c945fd3ba41796b /ares__timeval.c
parent3e04944084793a478a8b95d57da13dffc93f9336 (diff)
downloadc-ares-cd1f1d080c6eb417c51ba8709df430d74c2aed58.tar.gz
c-ares-cd1f1d080c6eb417c51ba8709df430d74c2aed58.tar.bz2
c-ares-cd1f1d080c6eb417c51ba8709df430d74c2aed58.zip
fallback to gettimeofday when monotonic clock is unavailable at run-time
Diffstat (limited to 'ares__timeval.c')
-rw-r--r--ares__timeval.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/ares__timeval.c b/ares__timeval.c
index c3f39f5..7437b5a 100644
--- a/ares__timeval.c
+++ b/ares__timeval.c
@@ -46,9 +46,24 @@ struct timeval ares__tvnow(void)
*/
struct timeval now;
struct timespec tsnow;
- (void)clock_gettime(CLOCK_MONOTONIC, &tsnow);
- now.tv_sec = tsnow.tv_sec;
- now.tv_usec = tsnow.tv_nsec / 1000;
+ if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
+ now.tv_sec = tsnow.tv_sec;
+ now.tv_usec = tsnow.tv_nsec / 1000;
+ }
+ /*
+ ** Even when the configure process has truly detected monotonic clock
+ ** availability, it might happen that it is not actually available at
+ ** run-time. When this occurs simply fallback to other time source.
+ */
+#ifdef HAVE_GETTIMEOFDAY
+ else
+ (void)gettimeofday(&now, NULL);
+#else
+ else {
+ now.tv_sec = (long)time(NULL);
+ now.tv_usec = 0;
+ }
+#endif
return now;
}