X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=libtest%2Fwait.h;h=f81a29ad85e0762d5124af8908cf3c52a9207464;hb=0792d5bdd0b2a352cce1a4cb084eca19b15acc56;hp=c6c3f966d84a79fcbddd9f167cc515d8e3992be1;hpb=e7874648bee9f91ba5f3428bcd821868ef71e1c0;p=m6w6%2Flibmemcached diff --git a/libtest/wait.h b/libtest/wait.h index c6c3f966..f81a29ad 100644 --- a/libtest/wait.h +++ b/libtest/wait.h @@ -24,6 +24,7 @@ #include #include +#include #include @@ -63,6 +64,30 @@ public: } } + 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); + } + } + bool successful() const { return _successful;