From: Brian Aker Date: Tue, 13 Mar 2012 16:05:25 +0000 (-0700) Subject: Merge from libtest. X-Git-Tag: 1.0.5~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=062e78da580009318a84372a7e117ab2a38869cb;p=awesomized%2Flibmemcached Merge from libtest. --- diff --git a/libtest/http.cc b/libtest/http.cc index 1a0a10ec..920fd021 100644 --- a/libtest/http.cc +++ b/libtest/http.cc @@ -20,6 +20,7 @@ */ #include + #include #if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H @@ -28,6 +29,39 @@ class CURL; #endif + +static void cleanup_curl(void) +{ +#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H + curl_global_cleanup(); +#endif +} + +static void initialize_curl_startup() +{ +#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H + if (curl_global_init(CURL_GLOBAL_ALL)) + { + fatal_message("curl_global_init(CURL_GLOBAL_ALL) failed"); + } +#endif + + if (atexit(cleanup_curl)) + { + fatal_message("atexit() failed"); + } +} + +static pthread_once_t start_key_once= PTHREAD_ONCE_INIT; +void initialize_curl(void) +{ + int ret; + if (pthread_once(&start_key_once, initialize_curl_startup) != 0) + { + fatal_message(strerror(ret)); + } +} + namespace libtest { namespace http { @@ -59,6 +93,13 @@ static void init(CURL *curl, const std::string& url) } } +HTTP::HTTP(const std::string& url_arg) : + _url(url_arg), + _response(0) +{ + initialize_curl(); +} + bool GET::execute() { if (HAVE_LIBCURL) diff --git a/libtest/http.hpp b/libtest/http.hpp index 012d7a07..bbc23b97 100644 --- a/libtest/http.hpp +++ b/libtest/http.hpp @@ -28,10 +28,7 @@ namespace http { class HTTP { public: - HTTP(const std::string& url_arg) : - _url(url_arg), - _response(0) - { } + HTTP(const std::string& url_arg); virtual bool execute()= 0; diff --git a/libtest/memcached.cc b/libtest/memcached.cc index 678c3cf1..5327e9b8 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -123,7 +123,7 @@ public: bool ping() { // Memcached is slow to start, so we need to do this - if (not pid_file().empty()) + if (pid_file().empty() == false) { if (wait_for_pidfile() == false) { @@ -137,7 +137,7 @@ public: if (has_socket()) { - ret= libmemcached_util_ping(socket().c_str(), 0, &rc); + ret= libmemcached_util_ping(socket().c_str(), 0, &rc); } else { @@ -344,7 +344,11 @@ public: class MemcachedSaSL : public Memcached { public: - MemcachedSaSL(const std::string& host_arg, const in_port_t port_arg, const bool is_socket_arg, const std::string& username_arg, const std::string &password_arg) : + MemcachedSaSL(const std::string& host_arg, + const in_port_t port_arg, + const bool is_socket_arg, + const std::string& username_arg, + const std::string &password_arg) : Memcached(host_arg, port_arg, is_socket_arg, username_arg, password_arg) { } @@ -460,7 +464,7 @@ bool Memcached::build(size_t argc, const char *argv[]) bool MemcachedLight::build(size_t argc, const char *argv[]) { - for (int x= 0 ; x < argc ; x++) + for (size_t x= 0 ; x < argc ; x++) { add_option(argv[x]); } diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 5be04f98..579f901c 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -328,7 +328,7 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons /* We will now cycle the server we have created. */ - if (not server->cycle()) + if (server->cycle() == false) { Error << "Could not start up server " << *server; delete server; diff --git a/libtest/test.cc b/libtest/test.cc index d367603d..cafc48d4 100644 --- a/libtest/test.cc +++ b/libtest/test.cc @@ -36,10 +36,6 @@ #include -#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H -#include -#endif - #ifndef __INTEL_COMPILER #pragma GCC diagnostic ignored "-Wold-style-cast" #endif @@ -75,32 +71,11 @@ static long int timedif(struct timeval a, struct timeval b) return s + us; } -static void cleanup_curl(void) -{ -#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H - curl_global_cleanup(); -#endif -} - #include #include int main(int argc, char *argv[]) { -#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H - if (curl_global_init(CURL_GLOBAL_ALL)) - { - Error << "curl_global_init(CURL_GLOBAL_ALL) failed"; - return EXIT_FAILURE; - } -#endif - - if (atexit(cleanup_curl)) - { - Error << "atexit() failed"; - return EXIT_FAILURE; - } - bool opt_repeat= false; std::string collection_to_run; @@ -451,13 +426,13 @@ cleanup: { std::cerr << e.what() << std::endl; } - catch (std::bad_alloc& e) + catch (std::exception& e) { std::cerr << e.what() << std::endl; } catch (...) { - std::cerr << "Unknown exception halted execution" << std::endl; + std::cerr << "Unknown exception halted execution." << std::endl; } return exit_code;