]> granicus.if.org Git - libevent/commitdiff
detect CLOCK_MONOTONIC at runtime for evdns
authorNiels Provos <provos@gmail.com>
Wed, 2 Jul 2008 04:39:09 +0000 (04:39 +0000)
committerNiels Provos <provos@gmail.com>
Wed, 2 Jul 2008 04:39:09 +0000 (04:39 +0000)
svn:r896

ChangeLog
evdns.c

index 2e22a9ba4bf4aedc151f3653ff0a0af84de013d3..f19cbd2201aa8cdef64ce950d249a83e61dd7547 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -114,6 +114,7 @@ Changes in current version:
  o Correct handling of trailing headers in chunked replies; from Scott Lamb.
  o Support multi-line HTTP headers; based on a patch from Moshe Litvin
  o Reject negative Content-Length headers; anonymous bug report
+ o Detect CLOCK_MONOTONIC at runtime for evdns; anonymous bug report   
        
 Changes in 1.4.0:
  o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
diff --git a/evdns.c b/evdns.c
index 762e4bc50f2a9a67e3d4b506c2635b20adf64c56..e44152ef6caa7b5c29f1cb75495e9a09421a6953 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -1056,12 +1056,16 @@ default_transaction_id_fn(void)
        u16 trans_id;
 #ifdef DNS_USE_CPU_CLOCK_FOR_ID
        struct timespec ts;
+       static int clkid = -1;
+       if (clkid == -1) {
+               clkid = CLOCK_REALTIME;
 #ifdef CLOCK_MONOTONIC
-       if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
-#else
-       if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
+               if (clock_gettime(CLOCK_MONOTONIC, &ts) != -1)
+                       clkid = CLOCK_MONOTONIC;
 #endif
-       event_err(1, "clock_gettime");
+       }
+       if (clock_gettime(clkid, &ts) == -1)
+               event_err(1, "clock_gettime");
        trans_id = ts.tv_nsec & 0xffff;
 #endif