2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
21 #include <unordered_map>
27 using arg_func_t = function<string(string)>;
28 using arg_t = variant<string, arg_func_t>;
29 using arg_pair_t = pair<arg_t, arg_t>;
30 using argv_t = vector<variant<arg_t, arg_pair_t>>;
32 explicit Server(string binary_ = "false", argv_t args_ = {});
36 Server(const Server &s);
37 Server &operator=(const Server &s);
39 Server(Server &&s) { *this = move(s); };
40 Server &operator=(Server &&s) {
41 binary = exchange(s.binary, "false");
42 args = exchange(s.args, {});
43 pid = exchange(s.pid, 0);
44 pipe = exchange(s.pipe, -1);
45 status = exchange(s.status, 0);
46 signalled = exchange(s.signalled, {});
47 socket_or_port = exchange(s.socket_or_port, {});
48 output = exchange(s.output, {});
54 const string &getBinary() const;
55 const argv_t &getArgs() const;
56 const socket_or_port_t &getSocketOrPort() const;
61 ChildProc(pid_t pid_, int pipe_)
65 optional<ChildProc> start();
68 bool signal(int signo = SIGTERM);
71 bool ensureListening();
73 bool wait(int flags = 0);
84 unordered_map<int, unsigned> signalled;
85 socket_or_port_t socket_or_port = 11211;
88 [[nodiscard]] vector<char *> createArgv();
89 optional<string> handleArg(vector<char *> &arr, const string &arg, const arg_func_t &next_arg);
92 inline ostream &operator<<(ostream &out, const socket_or_port_t sop) {
93 if (holds_alternative<string>(sop)) {
94 out << get<string>(sop);
96 out << ":" << get<int>(sop);
101 inline ostream &operator<<(ostream &out, const Server &server) {
102 out << "Server{binary=" << server.getBinary() << ",pid=" << server.getPid()
103 << ",conn=" << server.getSocketOrPort() << "}";