00001
00002
00003
00004
00005
00006
00007
00008
#ifndef __WVTIMEUTILS_H
00009
#define __WVTIMEUTILS_H
00010
00011
00012
#ifdef _WIN32
00013
#include "winsock2.h"
00014
#include <time.h>
00015
#else
00016
#include <sys/time.h>
00017
#endif
00018
00019 typedef struct timeval
WvTime;
00020
00021 static const WvTime wvtime_zero = {
00022 0, 0
00023 };
00024
00025
00026 time_t
msecdiff(
const WvTime &a,
const WvTime &b);
00027
00028
00029
WvTime wvtime();
00030
00031
00032
WvTime msecadd(
const WvTime &a, time_t msec);
00033
00034
00035
WvTime tvdiff(
const WvTime &a,
const WvTime &b);
00036
00037
00038 inline void normalize(WvTime &tv)
00039 {
00040 tv.tv_sec += tv.tv_usec / 1000000;
00041 tv.tv_usec %= 1000000;
00042 }
00043
00044
00045 inline bool operator< (
const WvTime &a,
00046
const struct timeval &b)
00047 {
00048
return a.tv_sec < b.tv_sec || (a.tv_sec == b.tv_sec
00049 && a.tv_usec < b.tv_usec);
00050 }
00051
00052 inline bool operator== (
const WvTime &a,
00053
const struct timeval &b)
00054 {
00055
return a.tv_sec == b.tv_sec && a.tv_usec == b.tv_usec;
00056 }
00057
00058
#endif // __WVTIMEUTILS_H