X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=libtest%2Fhttp.cc;h=8c36371d0827529aab2db90c5155e2908fc8a97c;hb=2e41f2aa7540640d02892f46bd16871e4581f3cf;hp=1a0a10ec0525a973368aa0283bdaec3abc57d3af;hpb=168c52f7a08866dbf2f151123ecf2bffbe7a5b0f;p=awesomized%2Flibmemcached diff --git a/libtest/http.cc b/libtest/http.cc index 1a0a10ec..8c36371d 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 ((ret= pthread_once(&start_key_once, initialize_curl_startup)) != 0) + { + fatal_message(strerror(ret)); + } +} + namespace libtest { namespace http { @@ -36,8 +70,6 @@ namespace http { extern "C" size_t http_get_result_callback(void *ptr, size_t size, size_t nmemb, void *data) { - size_t body_size= size * nmemb; - vchar_t *_body= (vchar_t*)data; _body->resize(size * nmemb); @@ -59,8 +91,17 @@ 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() { + (void)init; + if (HAVE_LIBCURL) { #if defined(HAVE_LIBCURL) && HAVE_LIBCURL