X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fhttp.cc;h=8c36371d0827529aab2db90c5155e2908fc8a97c;hb=1dff98bcffc7555e0255af25f7de26cb8eb42d32;hp=5309d50447a7dea2bdbadc047e2caea445917dc3;hpb=70d0d339d06cbe6b35ef0efc4fd3d7e8f92b6a01;p=m6w6%2Flibmemcached diff --git a/libtest/http.cc b/libtest/http.cc index 5309d504..8c36371d 100644 --- a/libtest/http.cc +++ b/libtest/http.cc @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include #if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H @@ -27,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 { @@ -35,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); @@ -58,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