#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;
+
+ bool startServer(Server &server);
};