X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=testing%2Flib%2FServer.hpp;h=5891dea27fb83dc3b0377e977c16aee1bfe924bf;hb=42f32d1f7926663821f7a76a34584484f7a4b412;hp=b411f4e34851e20f6f85aba8fd677da574e8cdf7;hpb=5e54d17fc535a901f384fcbf2cfd420f3a2e7a81;p=m6w6%2Flibmemcached diff --git a/testing/lib/Server.hpp b/testing/lib/Server.hpp index b411f4e3..5891dea2 100644 --- a/testing/lib/Server.hpp +++ b/testing/lib/Server.hpp @@ -1,86 +1,67 @@ #pragma once -#include "WaitForConn.hpp" +#include "common.hpp" #include -#include -#include -#include -#include -#include - -using namespace std; - class Server { - friend class Cluster; - public: - using str_args_t = vector; - using dyn_args_t = unordered_map>; - using socket_or_port_t = variant; -private: - string binary; - str_args_t str_args; - dyn_args_t dyn_args; - pid_t pid = 0; + friend class Cluster; - int status = 0; - unordered_map signalled; - socket_or_port_t socket_or_port{11211}; + using arg_func_t = function; + using arg_t = variant; + using arg_pair_t = pair; + using argv_t = vector>; -public: explicit - Server(string &&binary_, str_args_t &&str_args_ = {}, dyn_args_t &&dyn_args_ = {}) - : binary{binary_} - , str_args{str_args_} - , dyn_args{dyn_args_} - {} + Server(string &&binary_ = "false", argv_t && args_ = {}); - Server(string &&binary_, dyn_args_t &&dyn_args_) - : binary{binary_} - , str_args{} - , dyn_args{dyn_args_} - {} + ~Server(); - ~Server() { - stop(); - wait(); - } + Server(const Server &s); + Server &operator = (const Server &s); - Server &operator = (const Server &s) = default; - Server(const Server &s) = default; + Server(Server &&s) { + *this = move(s); + }; + Server &operator = (Server &&s) { + binary = exchange(s.binary, "false"); + args = exchange(s.args, {}); + pid = exchange(s.pid, 0); + status = exchange(s.status, 0); + signalled = exchange(s.signalled, {}); + socket_or_port = exchange(s.socket_or_port, {}); + return *this; + }; - Server &operator = (Server &&s) = default; - Server(Server &&s) = default; + pid_t getPid() const; - pid_t getPid() const { - return pid; - } + const string &getBinary() const; - const string &getBinary() const { - return binary; - } + const argv_t &getArgs() const; - const socket_or_port_t &getSocketOrPort() const { - return socket_or_port; - } + const socket_or_port_t &getSocketOrPort() const; optional start(); bool stop(); bool signal(int signo = SIGTERM); bool check(); - bool isListening(int max_timeout = 1000); + bool isListening(); bool wait(int flags = 0); bool tryWait(); private: - [[nodiscard]] - auto createArgv(); + string binary; + argv_t args; + pid_t pid = 0; + int status = 0; + unordered_map signalled; + socket_or_port_t socket_or_port = 11211; [[nodiscard]] - optional createSocket(); + vector createArgv(); + optional handleArg(vector &arr, const string &arg, const arg_func_t &next_arg); };