From 4403e950a95f28409d66bcd3a7594067a4b25eff Mon Sep 17 00:00:00 2001 From: frekky Date: Sat, 3 Oct 2015 22:14:30 +0800 Subject: [PATCH] Added timeval <-> millisecond util functions --- src/util.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util.h b/src/util.h index a0ee03b..9a99a49 100644 --- a/src/util.h +++ b/src/util.h @@ -18,7 +18,27 @@ #ifndef __UTIL_H__ #define __UTIL_H__ +#include +#include + char *get_resolvconf_addr(); void socket_setrtable(int fd, int rtable); +inline time_t +timeval_to_ms(struct timeval *tv) +{ + time_t ms = tv->tv_sec * 1000; + ms += (tv->tv_usec + 500) / 1000; + return ms; +} + +inline struct timeval +ms_to_timeval(time_t ms) +{ + struct timeval tv; + tv.tv_sec = ms / 1000; + tv.tv_usec = (ms - tv.tv_sec * 1000) * 1000; + return tv; +} + #endif