Added timeval <-> millisecond util functions

This commit is contained in:
frekky 2015-10-03 22:14:30 +08:00
parent 9ee23992c0
commit 4403e950a9

View File

@ -18,7 +18,27 @@
#ifndef __UTIL_H__ #ifndef __UTIL_H__
#define __UTIL_H__ #define __UTIL_H__
#include <time.h>
#include <sys/time.h>
char *get_resolvconf_addr(); char *get_resolvconf_addr();
void socket_setrtable(int fd, int rtable); 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 #endif