X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fwait.h;h=5f013cd3b01321f39ea3511837c2fb05e6bbcf6e;hb=c5bd49aee7b7bcb434cc526ff67d4bccddd4ba90;hp=33c4db54cb838d0c707345d2e199b82494deb074;hpb=9cd57ce737375540f6c3b5e2e3684160e5c4bfce;p=awesomized%2Flibmemcached diff --git a/libtest/wait.h b/libtest/wait.h index 33c4db54..5f013cd3 100644 --- a/libtest/wait.h +++ b/libtest/wait.h @@ -1,9 +1,8 @@ /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * uTest * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * All rights reserved. + * Data Differential YATL (i.e. libtest) library + * + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -39,6 +38,10 @@ #include #include +#include + +#include +#include namespace libtest { @@ -53,16 +56,50 @@ public: uint32_t this_wait; uint32_t retry; + if (filename.empty()) + { + _successful= false; + return; + } + + for (waited= 0, retry= 1; ; retry++, waited+= this_wait) + { + if (access(filename.c_str(), R_OK) == 0) + { + _successful= true; + break; + } + else if (waited >= timeout) + { + break; + } + + this_wait= retry * retry / 3 + 1; + 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 ((not access(filename.c_str(), R_OK)) or (waited >= timeout)) + if (kill(_pid_arg, 0) == 0) { _successful= true; break; } + else if (waited >= timeout) + { + break; + } this_wait= retry * retry / 3 + 1; - sleep(this_wait); + libtest::dream(this_wait, 0); } }