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 pipe = exchange(s.pipe, -1);
33 status = exchange(s.status, 0);
34 signalled = exchange(s.signalled, {});
35 socket_or_port = exchange(s.socket_or_port, {});
36 output = exchange(s.output, {});
42 const string &getBinary() const;
43 const argv_t &getArgs() const;
44 const socket_or_port_t &getSocketOrPort() const;
49 ChildProc(pid_t pid_, int pipe_)
55 optional<ChildProc> start();
58 bool signal(int signo = SIGTERM);
62 bool wait(int flags = 0);
73 unordered_map<int, unsigned> signalled;
74 socket_or_port_t socket_or_port = 11211;
78 vector<char *> createArgv();
79 optional<string> handleArg(vector<char *> &arr, const string &arg, const arg_func_t &next_arg);
82 inline ostream &operator << (ostream &out, const socket_or_port_t sop) {
83 if (holds_alternative<string>(sop)) {
84 out << get<string>(sop);
86 out << ":" << get<int>(sop);
91 inline ostream &operator << (ostream &out, const Server &server) {
92 out << "Server{binary=" << server.getBinary() << ",pid=" << server.getPid() << ",conn=" << server.getSocketOrPort() << "}";