6 #include <unordered_map>
13 using arg_func_t = function<string(string)>;
14 using arg_t = variant<string, arg_func_t>;
15 using arg_pair_t = pair<arg_t, arg_t>;
16 using argv_t = vector<variant<arg_t, arg_pair_t>>;
19 Server(string binary_ = "false", argv_t args_ = {});
23 Server(const Server &s);
24 Server &operator = (const Server &s);
29 Server &operator = (Server &&s) {
30 binary = exchange(s.binary, "false");
31 args = exchange(s.args, {});
32 pid = exchange(s.pid, 0);
33 pipe = exchange(s.pipe, -1);
34 status = exchange(s.status, 0);
35 signalled = exchange(s.signalled, {});
36 socket_or_port = exchange(s.socket_or_port, {});
37 output = exchange(s.output, {});
43 const string &getBinary() const;
44 const argv_t &getArgs() const;
45 const socket_or_port_t &getSocketOrPort() const;
50 ChildProc(pid_t pid_, int pipe_)
56 optional<ChildProc> start();
59 bool signal(int signo = SIGTERM);
62 bool ensureListening();
64 bool wait(int flags = 0);
76 unordered_map<int, unsigned> signalled;
77 socket_or_port_t socket_or_port = 11211;
81 vector<char *> createArgv();
82 optional<string> handleArg(vector<char *> &arr, const string &arg, const arg_func_t &next_arg);
85 inline ostream &operator << (ostream &out, const socket_or_port_t sop) {
86 if (holds_alternative<string>(sop)) {
87 out << get<string>(sop);
89 out << ":" << get<int>(sop);
94 inline ostream &operator << (ostream &out, const Server &server) {
95 out << "Server{binary=" << server.getBinary() << ",pid=" << server.getPid() << ",conn=" << server.getSocketOrPort() << "}";