Small code refactoring.

This commit is contained in:
LoRd_MuldeR 2023-12-07 23:21:11 +01:00
parent ce235738e6
commit f7ee6be8ea

View File

@ -1,29 +1,24 @@
diff --git "a/lib/nghttp2_time.c" "b/lib/nghttp2_time.c"
index 897556f..ab06684 100644
index 897556f..0e4a804 100644
--- "a/lib/nghttp2_time.c"
+++ "b/lib/nghttp2_time.c"
@@ -32,31 +32,15 @@
@@ -32,31 +32,16 @@
# include <sysinfoapi.h>
#endif /* HAVE_SYSINFOAPI_H */
-#if !defined(HAVE_GETTICKCOUNT64) || defined(__CYGWIN__)
-static uint64_t time_now_sec(void) {
- time_t t = time(NULL);
+uint64_t nghttp2_time_now_sec(void)
+{
+ FILETIME file_time;
+ ULARGE_INTEGER time_value;
+
+ GetSystemTimeAsFileTime(&file_time);
-
- if (t == -1) {
- return 0;
- }
+ time_value.LowPart = file_time.dwLowDateTime;
+ time_value.HighPart = file_time.dwHighDateTime;
-
- return (uint64_t)t;
+ return time_value.QuadPart / 10000000ULL;
+typedef union
+{
+ unsigned __int64 scalar;
+ FILETIME ft_struct;
}
-#endif /* !HAVE_GETTICKCOUNT64 || __CYGWIN__ */
-
@ -37,9 +32,15 @@ index 897556f..ab06684 100644
- if (rv == -1) {
- return time_now_sec();
- }
-
+ftime_t;
- return (uint64_t)tp.tv_sec;
-}
+uint64_t nghttp2_time_now_sec(void)
+{
+ ftime_t ftime;
+ GetSystemTimeAsFileTime(&(ftime.ft_struct));
+ return ftime.scalar / 10000000ULL;
}
-#else /* (!HAVE_CLOCK_GETTIME || __CYGWIN__) && !HAVE_GETTICKCOUNT64 */
-uint64_t nghttp2_time_now_sec(void) { return time_now_sec(); }
-#endif /* (!HAVE_CLOCK_GETTIME || __CYGWIN__) && !HAVE_GETTICKCOUNT64 */