From: Brian Aker Date: Sat, 20 Aug 2011 22:18:58 +0000 (-0700) Subject: Abstract out the wait X-Git-Tag: 0.52~12 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=45bd4941b48480653534255cee795684ed230084;p=awesomized%2Flibmemcached Abstract out the wait --- diff --git a/libtest/memcached.cc b/libtest/memcached.cc index 3e8e3fcd..daf6787c 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -87,9 +87,7 @@ public: // Memcached is slow to start, so we need to do this if (not pid_file().empty()) { - Wait wait(pid_file(), 0); - - if (error_is_ok and not wait.successful()) + if (error_is_ok and not wait_for_pidfile()) { Error << "Pidfile was not found:" << pid_file(); return -1; @@ -120,9 +118,7 @@ public: // Memcached is slow to start, so we need to do this if (not pid_file().empty()) { - Wait wait(pid_file(), 0); - - if (not wait.successful()) + if (not wait_for_pidfile()) { Error << "Pidfile was not found:" << pid_file(); return -1; @@ -230,9 +226,7 @@ public: // Memcached is slow to start, so we need to do this if (not pid_file().empty()) { - Wait wait(pid_file(), 0); - - if (error_is_ok and not wait.successful()) + if (error_is_ok and not wait_for_pidfile()) { Error << "Pidfile was not found:" << pid_file(); return -1; @@ -263,9 +257,7 @@ public: // Memcached is slow to start, so we need to do this if (not pid_file().empty()) { - Wait wait(pid_file(), 0); - - if (not wait.successful()) + if (not wait_for_pidfile()) { Error << "Pidfile was not found:" << pid_file(); return -1; diff --git a/libtest/server.cc b/libtest/server.cc index 5f0d59ec..8b8b8f3e 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -155,6 +155,13 @@ bool Server::command(std::string& command_arg) return false; } +bool Server::wait_for_pidfile() const +{ + Wait wait(pid_file(), 4); + + return wait.successful(); +} + bool Server::start() { // If we find that we already have a pid then kill it. diff --git a/libtest/server.h b/libtest/server.h index 123d1c32..b91f55b1 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -148,6 +148,8 @@ public: return (_pid > 1); } + bool wait_for_pidfile() const; + bool check_pid(pid_t pid_arg) const { return (pid_arg > 1); diff --git a/libtest/wait.h b/libtest/wait.h index d72a897b..391afa49 100644 --- a/libtest/wait.h +++ b/libtest/wait.h @@ -38,6 +38,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)