mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
dns: prefer monotonic clock for timeouts
Before this commit, DNS timeouts always used CLOCK_REALTIME, which could produce spurious timeouts or delays if wall time changed for whatever reason. Now we try CLOCK_MONOTONIC and only fall back to CLOCK_REALTIME when it is unavailable.
This commit is contained in:
parent
07616721f1
commit
7d756e1c04
1 changed files with 2 additions and 1 deletions
|
@ -25,7 +25,8 @@ static void cleanup(void *p)
|
||||||
static unsigned long mtime()
|
static unsigned long mtime()
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0 && errno == ENOSYS)
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
return (unsigned long)ts.tv_sec * 1000
|
return (unsigned long)ts.tv_sec * 1000
|
||||||
+ ts.tv_nsec / 1000000;
|
+ ts.tv_nsec / 1000000;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue