mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-25 02:55:15 +00:00
Added timeval <-> millisecond util functions
This commit is contained in:
parent
9ee23992c0
commit
4403e950a9
20
src/util.h
20
src/util.h
@ -18,7 +18,27 @@
|
||||
#ifndef __UTIL_H__
|
||||
#define __UTIL_H__
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user