X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fwait.h;h=e5cdcb3d4766ca4d0cece1e85eb69bf50bf67d9a;hb=f6879bcc9ff979bf313c7dd155ab2e1fee8605d8;hp=9c0ae79c9d6d5b25fe62222800bf317d61b406cc;hpb=c87f1a554cce74ac1ba3d4e7e9c2a1d2904e4766;p=awesomized%2Flibmemcached diff --git a/libtest/wait.h b/libtest/wait.h index 9c0ae79c..e5cdcb3d 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,9 @@ #include #include +#include + +#include namespace libtest { @@ -53,6 +55,12 @@ 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) @@ -66,13 +74,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(0, this_wait * 10000000); + } + } + + 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(0, this_wait * 10000000); } }