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