From 2be7e300be52f6d0c347a37e567b52889bfab4f7 Mon Sep 17 00:00:00 2001 From: leecoder Date: Mon, 23 Jun 2014 17:50:12 +0900 Subject: [PATCH 1/2] Async thr wait in basic_client_facade dtor --- boost/network/protocol/http/client/async_impl.hpp | 8 +++++--- boost/network/protocol/http/client/facade.hpp | 4 ++++ boost/network/protocol/http/client/sync_impl.hpp | 2 ++ libs/network/test/http/client_get_test.cpp | 12 ++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/boost/network/protocol/http/client/async_impl.hpp b/boost/network/protocol/http/client/async_impl.hpp index 768cdc923..e8053e519 100644 --- a/boost/network/protocol/http/client/async_impl.hpp +++ b/boost/network/protocol/http/client/async_impl.hpp @@ -63,10 +63,12 @@ struct async_client ~async_client() throw() { sentinel_.reset(); + } + + void wait_complete() { + sentinel_.reset(); if (lifetime_thread_.get()) { - if (lifetime_thread_->get_id() != boost::this_thread::get_id()) { - lifetime_thread_->join(); - } + lifetime_thread_->join(); lifetime_thread_.reset(); } } diff --git a/boost/network/protocol/http/client/facade.hpp b/boost/network/protocol/http/client/facade.hpp index 1132662c8..f974f74be 100644 --- a/boost/network/protocol/http/client/facade.hpp +++ b/boost/network/protocol/http/client/facade.hpp @@ -37,6 +37,10 @@ struct basic_client_facade { init_pimpl(options); } + virtual ~basic_client_facade() { + pimpl->wait_complete(); + } + response head(request const& request) { return pimpl->request_skeleton(request, "HEAD", diff --git a/boost/network/protocol/http/client/sync_impl.hpp b/boost/network/protocol/http/client/sync_impl.hpp index e724cf008..78c3484a4 100644 --- a/boost/network/protocol/http/client/sync_impl.hpp +++ b/boost/network/protocol/http/client/sync_impl.hpp @@ -73,6 +73,8 @@ struct sync_client service_ptr.reset(); } + void wait_complete() {} + basic_response request_skeleton(basic_request const& request_, string_type method, bool get_body, body_callback_function_type callback, diff --git a/libs/network/test/http/client_get_test.cpp b/libs/network/test/http/client_get_test.cpp index 1a2b558b1..8dbc92279 100644 --- a/libs/network/test/http/client_get_test.cpp +++ b/libs/network/test/http/client_get_test.cpp @@ -36,3 +36,15 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(https_client_get_test, client, client_types) { } #endif + +BOOST_AUTO_TEST_CASE_TEMPLATE(http_temp_client_get_test, client, client_types) { + typename client::request request("http://www.google.co.kr"); + typename client::response response; + BOOST_REQUIRE_NO_THROW ( response = client().get(request) ); + typename net::headers_range::type range = headers(response)["Content-Type"]; + BOOST_CHECK ( !boost::empty(range) ); + BOOST_REQUIRE_NO_THROW ( BOOST_CHECK ( body(response).size() != 0 ) ); + BOOST_CHECK_EQUAL ( response.version().substr(0,7), std::string("HTTP/1.") ); + BOOST_CHECK_EQUAL ( response.status(), 200u ); + BOOST_CHECK_EQUAL ( response.status_message(), std::string("OK") ); +} From c355924c140dfd5fae74989acba4fc845607700c Mon Sep 17 00:00:00 2001 From: leecoder Date: Wed, 25 Jun 2014 10:26:29 +0900 Subject: [PATCH 2/2] Update facade.hpp --- boost/network/protocol/http/client/facade.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boost/network/protocol/http/client/facade.hpp b/boost/network/protocol/http/client/facade.hpp index f974f74be..6bb097cd4 100644 --- a/boost/network/protocol/http/client/facade.hpp +++ b/boost/network/protocol/http/client/facade.hpp @@ -37,7 +37,7 @@ struct basic_client_facade { init_pimpl(options); } - virtual ~basic_client_facade() { + ~basic_client_facade() { pimpl->wait_complete(); }