flush [ci skip]
[m6w6/libmemcached] / testing / lib / Cluster.hpp
index d6a11a7ee79ea65e397d3fa0dfab03b997d88891..efc5eefdd93d15ba45fefbf9ee37f547536abf30 100644 (file)
@@ -1,34 +1,43 @@
 #pragma once
 
+#include "common.hpp"
 #include "Server.hpp"
 
-#include <map>
-#include <thread>
-
 class Cluster {
-private:
-  uint16_t count;
-  Server proto;
-  vector<Server> cluster;
-
-  map<pid_t, Server *> pids;
-
 public:
   explicit
-  Cluster(Server &&serv, uint16_t cnt = 0)
-  : count{cnt}
-  , proto{serv}
+  Cluster(Server &&serv, uint16_t cnt = 0);
+
+  ~Cluster();
+
+  Cluster(const Cluster &c) = delete;
+  Cluster &operator = (const Cluster &c) = delete;
+
+  Cluster(Cluster &&c)
+  : proto{}
   {
-    if (!cnt) {
-      count = thread::hardware_concurrency() ?: 4;
-    }
-    reset();
+    *this = move(c);
+  };
+  Cluster &operator = (Cluster &&c) {
+    count = exchange(c.count, 0);
+    proto = exchange(c.proto, Server{});
+    cluster = exchange(c.cluster, {});
+    pids = exchange(c.pids, {});
+    return *this;
   }
 
+  const vector<Server> &getServers() const;
+
   bool start();
   void stop();
   void reset();
   bool isStopped();
-  bool isListening(int max_timeout = 1000);
+  bool isListening();
   void wait();
+
+private:
+  uint16_t count;
+  Server proto;
+  vector<Server> cluster;
+  map<pid_t, Server *> pids;
 };