From: Adam Dickmeiss Date: Fri, 9 Apr 2010 09:25:47 +0000 (+0200) Subject: ztest delay: select(Unix) or Sleep(Win32) X-Git-Tag: v4.0.3~4 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=6efe941c2ccde0e5a7895ab63d4b876fd6396bfc;p=yaz-moved-to-github.git ztest delay: select(Unix) or Sleep(Win32) --- diff --git a/ztest/ztest.c b/ztest/ztest.c index 6d806b2..4ebf1c1 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -11,9 +11,16 @@ #include #include #include + +#if HAVE_SYS_TIME_H +#include +#endif #if HAVE_UNISTD_H #include #endif +#if HAVE_SYS_SELECT_H +#include +#endif #include #include @@ -188,18 +195,27 @@ static int parse_delay(struct delay *delayp, const char *value) return 0; } +static void ztest_sleep(double d) +{ +#ifdef WIN32 + Sleep( (DWORD) (d * 1000)); +#else + struct timeval tv; + tv.tv_sec = floor(d); + tv.tv_usec = (d - floor(d)) * 1000000; + select(0, 0, 0, 0, &tv); +#endif +} + static void do_delay(const struct delay *delayp) { double d = delayp->d1; if (d > 0.0) { - struct timeval tv; if (delayp->d2 > d) d += (rand()) * (delayp->d2 - d) / RAND_MAX; - tv.tv_sec = floor(d); - tv.tv_usec = (d - floor(d)) * 1000000; - select(0, 0, 0, 0, &tv); + ztest_sleep(d); } }