소스 검색

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.
A. Wilcox 2 년 전
부모
커밋
7d756e1c04
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      src/network/res_msend.c

+ 2 - 1
src/network/res_msend.c

@@ -25,7 +25,8 @@ static void cleanup(void *p)
 static unsigned long mtime()
 {
 	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
 		+ ts.tv_nsec / 1000000;
 }