X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fwait.h;h=f81a29ad85e0762d5124af8908cf3c52a9207464;hb=9f3c2098e91293e4d69b1d691fbf352e440309ff;hp=391afa4979fe9b897daa35d81ed8478012fff2fc;hpb=45bd4941b48480653534255cee795684ed230084;p=m6w6%2Flibmemcached diff --git a/libtest/wait.h b/libtest/wait.h index 391afa49..f81a29ad 100644 --- a/libtest/wait.h +++ b/libtest/wait.h @@ -24,6 +24,9 @@ #include #include +#include + +#include namespace libtest { @@ -57,13 +60,31 @@ public: } this_wait= retry * retry / 3 + 1; - sleep(this_wait); -#ifdef WIN32 - sleep(this_wait); -#else - struct timespec global_sleep_value= { this_wait, 0 }; - nanosleep(&global_sleep_value, NULL); -#endif + libtest::dream(this_wait, 0); + } + } + + Wait(const pid_t &_pid_arg, uint32_t timeout= 6) : + _successful(false) + { + uint32_t waited; + uint32_t this_wait; + uint32_t retry; + + for (waited= 0, retry= 1; ; retry++, waited+= this_wait) + { + if (kill(_pid_arg, 0) == 0) + { + _successful= true; + break; + } + else if (waited >= timeout) + { + break; + } + + this_wait= retry * retry / 3 + 1; + libtest::dream(this_wait, 0); } }