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 #if __clang__ && __clang_major__ <= 7
37 socket_or_port = s.socket_or_port;
38 s.socket_or_port = 11211;
40 socket_or_port = exchange(s.socket_or_port, 11211);
42 output = exchange(s.output, {});
48 const string &getBinary() const;
49 const argv_t &getArgs() const;
50 const socket_or_port_t &getSocketOrPort() const;
55 ChildProc(pid_t pid_, int pipe_)
61 optional<ChildProc> start();
64 bool signal(int signo = SIGTERM);
67 bool ensureListening();
69 bool wait(int flags = 0);
81 unordered_map<int, unsigned> signalled;
82 socket_or_port_t socket_or_port = 11211;
86 vector<char *> createArgv();
87 optional<string> handleArg(vector<char *> &arr, const string &arg, const arg_func_t &next_arg);
90 inline ostream &operator << (ostream &out, const socket_or_port_t sop) {
91 if (holds_alternative<string>(sop)) {
92 out << get<string>(sop);
94 out << ":" << get<int>(sop);
99 inline ostream &operator << (ostream &out, const Server &server) {
100 out << "Server{binary=" << server.getBinary() << ",pid=" << server.getPid() << ",conn=" << server.getSocketOrPort() << "}";