X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fwait.h;h=f81a29ad85e0762d5124af8908cf3c52a9207464;hb=3998b1125e1b9f8ebd2c963aa6f8d60131bc97c4;hp=c6c3f966d84a79fcbddd9f167cc515d8e3992be1;hpb=d2bb5f47f9b0ea0da06c3db435b2d3eca27d92d1;p=awesomized%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;