From 1fb1bb59c936ea4d752a12db3d73f490e5b7b6a1 Mon Sep 17 00:00:00 2001 From: bustico Date: Thu, 20 Jun 2013 17:23:52 +0000 Subject: initial windows support for ping/pong implementation, to be tested and validated --- debian/changelog | 6 ++++++ src/ivy.c | 1 + src/timer.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/timer.h | 12 ++++++++++++ 4 files changed, 65 insertions(+) diff --git a/debian/changelog b/debian/changelog index e6a5634..c31cf2e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +ivy-c (3.14.2) unstable; urgency=low + + * initial windows support for ping/pong implementation, to be tested and validated + + -- Alexandre Bustico Thu, 20 June 2013 18:37:00 +0200 + ivy-c (3.14.1) unstable; urgency=low * fix compilation warning diff --git a/src/ivy.c b/src/ivy.c index a855094..87717ee 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -27,6 +27,7 @@ #ifdef WIN32 #include #include +#include "timer.h" #define snprintf _snprintf #ifdef __MINGW32__ // should be removed in when defined in MinGW include of ws2tcpip.h diff --git a/src/timer.c b/src/timer.c index 7f9394a..4864321 100644 --- a/src/timer.c +++ b/src/timer.c @@ -187,3 +187,49 @@ void TimerScan() } } + +#ifdef WIN32 + +#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) + #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +#else + #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +#endif + + +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + FILETIME ft; + unsigned __int64 tmpres = 0; + static int tzflag = 0; + + if (NULL != tv) + { + GetSystemTimeAsFileTime(&ft); + + tmpres |= ft.dwHighDateTime; + tmpres <<= 32; + tmpres |= ft.dwLowDateTime; + + tmpres /= 10; /*convert into microseconds*/ + /*converting file time to unix epoch*/ + tmpres -= DELTA_EPOCH_IN_MICROSECS; + tv->tv_sec = (long)(tmpres / 1000000UL); + tv->tv_usec = (long)(tmpres % 1000000UL); + } + + if (NULL != tz) + { + if (!tzflag) + { + _tzset(); + tzflag++; + } + tz->tz_minuteswest = _timezone / 60; + tz->tz_dsttime = _daylight; + } + + return 0; +} + +#endif diff --git a/src/timer.h b/src/timer.h index 6e31dd7..accad5b 100644 --- a/src/timer.h +++ b/src/timer.h @@ -34,6 +34,18 @@ void TimerModify( TimerId id, long timeout ); void TimerRemove( TimerId id ); + + // implemetation of gettimeofday for windows +#ifdef WIN32 +#include "time.h" +struct timezone +{ + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; +int gettimeofday(struct timeval *tv, struct timezone *tz); +#endif + /* Interface avec select */ struct timeval *TimerGetSmallestTimeout(); -- cgit v1.1