c6c0cb926aa776b6d1672d4f4d51d4d128eba83a
[m6w6/libmemcached] / test / lib / Cluster.hpp
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #pragma once
17
18 #include "common.hpp"
19 #include "Server.hpp"
20
21 class Cluster {
22 public:
23 explicit Cluster(Server serv, uint16_t cnt = 0);
24
25 ~Cluster();
26
27 Cluster(const Cluster &c) = delete;
28 Cluster &operator=(const Cluster &c) = delete;
29
30 Cluster(Cluster &&c)
31 : proto{} {
32 *this = move(c);
33 };
34 Cluster &operator=(Cluster &&c) {
35 count = exchange(c.count, 0);
36 proto = exchange(c.proto, Server{});
37 cluster = exchange(c.cluster, {});
38 pids = exchange(c.pids, {});
39 return *this;
40 }
41
42 const vector<Server> &getServers() const;
43
44 bool start();
45 void stop();
46 void reset();
47 bool isStopped();
48 bool isListening();
49 void wait();
50
51 private:
52 uint16_t count;
53 Server proto;
54 vector<Server> cluster;
55 map<pid_t, Server *> pids;
56
57 bool startServer(Server &server);
58 };