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>>;
18 Server(string binary_ = "false", argv_t args_ = {});
22 Server(const Server &s);
23 Server &operator = (const Server &s);
28 Server &operator = (Server &&s) {
29 binary = exchange(s.binary, "false");
30 args = exchange(s.args, {});
31 pid = exchange(s.pid, 0);
32 status = exchange(s.status, 0);
33 signalled = exchange(s.signalled, {});
34 socket_or_port = exchange(s.socket_or_port, {});
40 const string &getBinary() const;
42 const argv_t &getArgs() const;
44 const socket_or_port_t &getSocketOrPort() const;
46 optional<pid_t> start();
49 bool signal(int signo = SIGTERM);
53 bool wait(int flags = 0);
61 unordered_map<int, unsigned> signalled;
62 socket_or_port_t socket_or_port = 11211;
65 vector<char *> createArgv();
66 optional<string> handleArg(vector<char *> &arr, const string &arg, const arg_func_t &next_arg);
69 inline ostream &operator << (ostream &out, const socket_or_port_t sop) {
70 if (holds_alternative<string>(sop)) {
71 out << get<string>(sop);
78 inline ostream &operator << (ostream &out, const Server &server) {
79 out << "Server{binary=" << server.getBinary() << ",pid=" << server.getPid() << ",conn=" << server.getSocketOrPort() << "}";