X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fserver.h;h=00f29cd837b19c9c21630c7fbbf0be835d942b04;hb=d52b943dbd966665962fb4af269688effa8fc81e;hp=0aef86f93ce28ee57747a18329499e32da1b726c;hpb=349ca737f30ff0b6c3c71034f0930660663fa360;p=m6w6%2Flibmemcached diff --git a/libtest/server.h b/libtest/server.h index 0aef86f9..00f29cd8 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ * Copyright (C) 2006-2009 Brian Aker * All rights reserved. * @@ -6,26 +7,145 @@ * the COPYING file in the parent directory for full text. */ -/* - Server startup and shutdown functions. -*/ -#ifdef __cplusplus -extern "C" { -#endif +#pragma once + +#include +#include +#include +#include +#include +#include + +#define SERVERS_TO_CREATE 5 + +struct server_st; + +typedef pid_t (test_server_getpid)(server_st &); +typedef bool (test_server_ping)(server_st &); + +struct server_st { +private: + bool _used; + pid_t _pid; + in_port_t _port; + char pid_file[FILENAME_MAX]; // Did we start it, or was it just sitting there? + std::string _command; + test_server_getpid *__get_pid; + test_server_ping *__ping; + std::string _hostname; + +public: + server_st(in_port_t port_arg, test_server_getpid *, test_server_ping *); + + server_st(const std::string &socket_file, test_server_getpid *, test_server_ping *); + + void set_methods(test_server_getpid *get_pid_arg, test_server_ping *ping_arg) + { + __get_pid= get_pid_arg; + __ping= ping_arg; + } + + const char *hostname() const + { + if (_hostname.empty()) + return ""; + + return _hostname.c_str(); + } + + bool ping() + { + if (__ping) + return __ping(*this); + + return false; + } + + pid_t get_pid() + { + if (__get_pid) + return _pid= __get_pid(*this); + + return -1; + } + + void set_port(in_port_t arg) + { + _port= arg; + } -#include + in_port_t port() const + { + return _port; + } -typedef struct server_startup_st server_startup_st; + bool has_port() const + { + return (_port != 0); + } + + void set_command(const char *arg) + { + _command= arg; + } + + void set_used() + { + _used= true; + } + + pid_t pid(); + + bool is_used() const + { + return _used; + } + + ~server_st(); + + bool has_pid() + { + return (_pid > 1); + } + + bool is_socket() const + { + return _hostname[0] == '/'; + } + + bool kill(); + bool start(); + +private: + void reset_pid(); +}; + +std::ostream& operator<<(std::ostream& output, const server_st &arg); struct server_startup_st { - uint8_t count; + uint32_t count; uint8_t udp; - memcached_server_st *servers; - char *server_list; + std::string server_list; + std::vector servers; + + server_startup_st() : + count(SERVERS_TO_CREATE), + udp(0) + { } + + void shutdown(); + void push_server(server_st *); + + ~server_startup_st(); }; -void server_startup(server_startup_st *construct); +#ifdef __cplusplus +extern "C" { +#endif + + +bool server_startup(server_startup_st *construct); void server_shutdown(server_startup_st *construct); #ifdef __cplusplus