#include "Server.hpp"
-#include "Connection.hpp"
+#include "Retry.hpp"
#include "ForkAndExec.hpp"
#include <sys/wait.h>
return true;
}
+bool Server::ensureListening() {
+ return Retry{[this] {
+ again:
+ start();
+ if (!isListening()) {
+ if (tryWait()){
+ goto again;
+ }
+ }
+ return isListening();
+ }}();
+}
+
bool Server::stop() {
if (!pid) {
return true;
bool signal(int signo = SIGTERM);
bool check();
bool isListening();
+ bool ensureListening();
bool wait(int flags = 0);
bool tryWait();
MemcachedPtr memc;
LoneReturnMatcher test{*memc};
- server.start();
- Retry{[&server] { return server.isListening(); }}();
+ REQUIRE(server.ensureListening());
auto port = get<int>(server.getSocketOrPort());
auto comm = "memcat --servers=localhost:" + to_string(port) + " ";
MemcachedPtr memc;
LoneReturnMatcher test{*memc};
- server.start();
- Retry{[&server] { return server.isListening(); }}();
+ REQUIRE(server.ensureListening());
auto port = get<int>(server.getSocketOrPort());
auto comm = "memcp --servers=localhost:" + to_string(port) + " ";
MemcachedPtr memc;
LoneReturnMatcher test{*memc};
- server.start();
- Retry{[&server] { return server.isListening(); }}();
+ REQUIRE(server.ensureListening());
auto port = get<int>(server.getSocketOrPort());
auto comm = "memdump --servers=localhost:" + to_string(port) + " ";
MemcachedPtr memc;
LoneReturnMatcher test{*memc};
- server.start();
- Retry{[&server] { return server.isListening(); }}();
+ REQUIRE(server.ensureListening());
auto port = get<int>(server.getSocketOrPort());
auto comm = "memexist --servers=localhost:" + to_string(port) + " ";
MemcachedPtr memc;
LoneReturnMatcher test{*memc};
- server.start();
- Retry{[&server] { return server.isListening(); }}();
+ REQUIRE(server.ensureListening());
auto port = get<int>(server.getSocketOrPort());
auto comm = "memflush --servers=localhost:" + to_string(port) + " ";