From: Niels Provos Date: Wed, 2 Jul 2008 04:39:09 +0000 (+0000) Subject: detect CLOCK_MONOTONIC at runtime for evdns X-Git-Tag: release-2.0.1-alpha~242 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=409236a77d40f234e93684e51eb5928c30854daa;p=libevent detect CLOCK_MONOTONIC at runtime for evdns svn:r896 --- diff --git a/ChangeLog b/ChangeLog index 2e22a9ba..f19cbd22 100644 --- 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 762e4bc5..e44152ef 100644 --- 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