flush [ci skip]
[awesomized/libmemcached] / testing / lib / Server.hpp
1 #pragma once
2
3 #include "common.hpp"
4
5 #include <csignal>
6
7 class Server {
8 public:
9
10 friend class Cluster;
11
12 using arg_func_t = function<string(string)>;
13 using arg_t = variant<string, arg_func_t>;
14 using arg_pair_t = pair<arg_t, arg_t>;
15 using argv_t = vector<variant<arg_t, arg_pair_t>>;
16
17 explicit
18 Server(string &&binary_, argv_t && args_ = {});
19
20 ~Server();
21
22 Server(const Server &s);
23 Server &operator = (const Server &s);
24
25 Server &operator = (Server &&s) = default;
26 Server(Server &&s) = default;
27
28 pid_t getPid() const;
29
30 const string &getBinary() const;
31
32 const argv_t &getArgs() const;
33
34 const socket_or_port_t &getSocketOrPort() const;
35
36 optional<pid_t> start();
37 bool stop();
38
39 bool signal(int signo = SIGTERM);
40 bool check();
41 bool isListening();
42
43 bool wait(int flags = 0);
44 bool tryWait();
45
46 private:
47 string binary;
48 argv_t args;
49 pid_t pid = 0;
50 int status = 0;
51 unordered_map<int, unsigned> signalled;
52 socket_or_port_t socket_or_port = 11211;
53
54 [[nodiscard]]
55 vector<char *> createArgv();
56 optional<string> handleArg(vector<char *> &arr, const string &arg, const arg_func_t &next_arg);
57 };