00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifdef MACOSX
00033 #include <stdint.h>
00034 #include <sys/types.h>
00035 #include <signal.h>
00036 #endif
00037 #include "EventTime.h"
00038 #ifdef _WIN32
00039 #include <windows.h>
00040 #else
00041 #include <sys/select.h>
00042 #include <sys/time.h>
00043 #endif
00044
00045
00046
00047 #ifdef SOCKETS_NAMESPACE
00048 namespace SOCKETS_NAMESPACE {
00049 #endif
00050
00051
00052 EventTime::EventTime() : m_time(Tick())
00053 {
00054 }
00055
00056
00057 EventTime::EventTime(mytime_t sec,long usec) : m_time(Tick())
00058 {
00059 m_time += sec * 1000000 + usec;
00060 }
00061
00062
00063 EventTime::~EventTime()
00064 {
00065 }
00066
00067
00068 mytime_t EventTime::Tick()
00069 {
00070 mytime_t t;
00071 #ifdef _WIN32
00072 FILETIME ft;
00073 GetSystemTimeAsFileTime(&ft);
00074 t = ft.dwHighDateTime;
00075 t = t << 32;
00076 t += ft.dwLowDateTime;
00077 t /= 10;
00078 #else
00079 struct timeval tv;
00080 struct timezone tz;
00081 gettimeofday(&tv, &tz);
00082 t = tv.tv_sec;
00083 t *= 1000000;
00084 t += tv.tv_usec;
00085 #endif
00086 return t;
00087 }
00088
00089
00090 EventTime EventTime::operator - (const EventTime& x) const
00091 {
00092 EventTime t;
00093 t.m_time = m_time - x.m_time;
00094 return t;
00095 }
00096
00097
00098 bool EventTime::operator < (const EventTime& x) const
00099 {
00100 return m_time < x.m_time;
00101 }
00102
00103
00104 #ifdef SOCKETS_NAMESPACE
00105 }
00106 #endif
00107