From d5df753e415b954c92092145bd89c97a09d6a58d Mon Sep 17 00:00:00 2001 From: David Mugnai Date: Mon, 19 Sep 2016 00:08:58 +0200 Subject: [PATCH 1/4] new test to cover the `ready()` wrapper it does not compile now --- libs/network/test/http/CMakeLists.txt | 1 + .../test/http/client_get_ready_test.cpp | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 libs/network/test/http/client_get_ready_test.cpp diff --git a/libs/network/test/http/CMakeLists.txt b/libs/network/test/http/CMakeLists.txt index f7857d97e..2948d5b92 100644 --- a/libs/network/test/http/CMakeLists.txt +++ b/libs/network/test/http/CMakeLists.txt @@ -38,6 +38,7 @@ if (Boost_FOUND) client_get_test client_get_different_port_test # client_get_timeout_test + client_get_ready_test client_get_streaming_test) foreach ( test ${TESTS} ) add_executable(cpp-netlib-http-${test} ${test}.cpp) diff --git a/libs/network/test/http/client_get_ready_test.cpp b/libs/network/test/http/client_get_ready_test.cpp new file mode 100644 index 000000000..1688ec3ed --- /dev/null +++ b/libs/network/test/http/client_get_ready_test.cpp @@ -0,0 +1,34 @@ +// Copyright 2010 Dean Michael Berris. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include "client_types.hpp" + +namespace net = boost::network; +namespace http = boost::network::http; +using tclock = std::chrono::high_resolution_clock; + +TYPED_TEST_CASE(HTTPClientTest, ClientTypes); + +TYPED_TEST(HTTPClientTest, GetTest) { + using client = TypeParam; + typename client::request request("http://cpp-netlib.org/"); + client client_; + auto response = client_.get(request); + while (!http::ready(response)) { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + auto t0 = tclock::now(); + auto data = body(response); + auto t1 = tclock::now(); + EXPECT_TRUE(response.status() == 200u || + (response.status() >= 300 && response.status() < 400)); + EXPECT_TRUE(data.size() > 0); + + // XXX we should find a better way to check if `ready()` has done his job + namespace c = std::chrono; + EXPECT_TRUE(c::duration_cast(t1-t0).count() < 1); +} From ecdae1ee72de81667ea04e60c46e0e1ec94800c1 Mon Sep 17 00:00:00 2001 From: David Mugnai Date: Mon, 19 Sep 2016 00:10:08 +0200 Subject: [PATCH 2/4] replace std::promise/std::shared_future with boost equivalents boost::shared_future has a richer api, notably it has the `is_ready()` method required by the `ready()` wrapper --- CMakeLists.txt | 2 +- .../directives/detail/string_value.hpp | 4 +-- .../message/modifiers/clear_headers.hpp | 6 ++-- boost/network/message/traits/body.hpp | 4 +-- boost/network/message/traits/destination.hpp | 4 +-- boost/network/message/traits/headers.hpp | 6 ++-- boost/network/message/traits/source.hpp | 4 +-- .../connection/async_protocol_handler.hpp | 29 ++++++++++--------- .../protocol/http/message/async_message.hpp | 24 +++++++-------- .../http/message/directives/status.hpp | 8 ++--- .../protocol/http/message/traits/status.hpp | 3 +- .../http/message/traits/status_message.hpp | 4 +-- .../protocol/http/message/traits/version.hpp | 4 +-- 13 files changed, 52 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe433101d..7d7c3d0e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ add_definitions(-DBOOST_TEST_DYN_LINK) # Always use multi-threaded Boost libraries. set(Boost_USE_MULTI_THREADED ON) -find_package(Boost 1.58.0 REQUIRED COMPONENTS system) +find_package(Boost 1.58.0 REQUIRED COMPONENTS system thread) if (CPP-NETLIB_ENABLE_HTTPS) find_package( OpenSSL ) diff --git a/boost/network/message/directives/detail/string_value.hpp b/boost/network/message/directives/detail/string_value.hpp index 53bea1546..8a3fa7d26 100644 --- a/boost/network/message/directives/detail/string_value.hpp +++ b/boost/network/message/directives/detail/string_value.hpp @@ -6,10 +6,10 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include +#include #include #include #include @@ -20,7 +20,7 @@ namespace detail { template struct string_value - : mpl::if_, std::shared_future::type>, + : mpl::if_, boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same, is_same >, diff --git a/boost/network/message/modifiers/clear_headers.hpp b/boost/network/message/modifiers/clear_headers.hpp index 1f54af0d9..ef758073f 100644 --- a/boost/network/message/modifiers/clear_headers.hpp +++ b/boost/network/message/modifiers/clear_headers.hpp @@ -6,11 +6,11 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include +#include #include namespace boost { @@ -34,8 +34,8 @@ template inline typename enable_if >, is_async >, void>::type clear_headers(Message const &message, Tag const &) { - std::promise header_promise; - std::shared_future headers_future( + boost::promise header_promise; + boost::shared_future headers_future( header_promise.get_future()); message.headers(headers_future); header_promise.set_value(typename Message::headers_container_type()); diff --git a/boost/network/message/traits/body.hpp b/boost/network/message/traits/body.hpp index 495fe2d9b..cd0c56b1f 100644 --- a/boost/network/message/traits/body.hpp +++ b/boost/network/message/traits/body.hpp @@ -8,12 +8,12 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include #include +#include #include namespace boost { @@ -27,7 +27,7 @@ template struct body : mpl::if_< is_async, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same #include #include #include #include #include +#include #include namespace boost { @@ -26,7 +26,7 @@ struct unsupported_tag; template struct destination : mpl::if_, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same #include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include namespace boost { namespace network { @@ -28,7 +28,7 @@ template struct header_key : mpl::if_< is_async, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same, @@ -40,7 +40,7 @@ template struct header_value : mpl::if_< is_async, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same, diff --git a/boost/network/message/traits/source.hpp b/boost/network/message/traits/source.hpp index ad037a4a6..17f9b188e 100644 --- a/boost/network/message/traits/source.hpp +++ b/boost/network/message/traits/source.hpp @@ -6,12 +6,12 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include #include +#include #include namespace boost { @@ -24,7 +24,7 @@ struct unsupported_tag; template struct source : mpl::if_, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same #include #include +#include namespace boost { namespace network { @@ -57,30 +58,30 @@ struct http_async_protocol_handler { // TODO(dberris): review parameter necessity. (void)get_body; - std::shared_future source_future( + boost::shared_future source_future( source_promise.get_future()); source(response_, source_future); - std::shared_future destination_future( + boost::shared_future destination_future( destination_promise.get_future()); destination(response_, destination_future); - std::shared_future::type> headers_future( + boost::shared_future::type> headers_future( headers_promise.get_future()); headers(response_, headers_future); - std::shared_future body_future(body_promise.get_future()); + boost::shared_future body_future(body_promise.get_future()); body(response_, body_future); - std::shared_future version_future( + boost::shared_future version_future( version_promise.get_future()); version(response_, version_future); - std::shared_future status_future( + boost::shared_future status_future( status_promise.get_future()); status(response_, status_future); - std::shared_future status_message_future( + boost::shared_future status_message_future( status_message_promise.get_future()); status_message(response_, status_message_future); } @@ -341,13 +342,13 @@ struct http_async_protocol_handler { typedef std::array::type, 1024> buffer_type; response_parser_type response_parser_; - std::promise version_promise; - std::promise status_promise; - std::promise status_message_promise; - std::promise::type> headers_promise; - std::promise source_promise; - std::promise destination_promise; - std::promise body_promise; + boost::promise version_promise; + boost::promise status_promise; + boost::promise status_message_promise; + boost::promise::type> headers_promise; + boost::promise source_promise; + boost::promise destination_promise; + boost::promise body_promise; buffer_type part; typename buffer_type::const_iterator part_begin; string_type partial_parsed; diff --git a/boost/network/protocol/http/message/async_message.hpp b/boost/network/protocol/http/message/async_message.hpp index bca9148b2..861f3adf6 100644 --- a/boost/network/protocol/http/message/async_message.hpp +++ b/boost/network/protocol/http/message/async_message.hpp @@ -9,13 +9,13 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include // FIXME move this out to a trait #include #include +#include namespace boost { namespace network { @@ -56,31 +56,31 @@ struct async_message { string_type const status_message() const { return status_message_.get(); } - void status_message(std::shared_future const& future) const { + void status_message(boost::shared_future const& future) const { status_message_ = future; } string_type const version() const { return version_.get(); } - void version(std::shared_future const& future) const { + void version(boost::shared_future const& future) const { version_ = future; } std::uint16_t status() const { return status_.get(); } - void status(std::shared_future const& future) const { + void status(boost::shared_future const& future) const { status_ = future; } string_type const source() const { return source_.get(); } - void source(std::shared_future const& future) const { + void source(boost::shared_future const& future) const { source_ = future; } string_type const destination() const { return destination_.get(); } - void destination(std::shared_future const& future) const { + void destination(boost::shared_future const& future) const { destination_ = future; } @@ -95,7 +95,7 @@ struct async_message { return *retrieved_headers_; } - void headers(std::shared_future const& future) + void headers(boost::shared_future const& future) const { headers_ = future; } @@ -112,7 +112,7 @@ struct async_message { string_type const body() const { return body_.get(); } - void body(std::shared_future const& future) const { + void body(boost::shared_future const& future) const { body_ = future; } @@ -132,13 +132,13 @@ struct async_message { } private: - mutable std::shared_future status_message_, version_, source_, + mutable boost::shared_future status_message_, version_, source_, destination_; - mutable std::shared_future status_; - mutable std::shared_future headers_; + mutable boost::shared_future status_; + mutable boost::shared_future headers_; mutable headers_container_type added_headers; mutable std::set removed_headers; - mutable std::shared_future body_; + mutable boost::shared_future body_; mutable boost::optional retrieved_headers_; friend struct boost::network::http::impl::ready_wrapper; diff --git a/boost/network/protocol/http/message/directives/status.hpp b/boost/network/protocol/http/message/directives/status.hpp index 010ad2f2a..f64cb94d3 100644 --- a/boost/network/protocol/http/message/directives/status.hpp +++ b/boost/network/protocol/http/message/directives/status.hpp @@ -7,11 +7,11 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include +#include #include #include #include @@ -25,18 +25,18 @@ struct basic_response; struct status_directive { - boost::variant > + boost::variant > status_; explicit status_directive(std::uint16_t status) : status_(status) {} - explicit status_directive(std::shared_future const &status) + explicit status_directive(boost::shared_future const &status) : status_(status) {} status_directive(status_directive const &other) : status_(other.status_) {} template - struct value : mpl::if_, std::shared_future, + struct value : mpl::if_, boost::shared_future, std::uint16_t> {}; template diff --git a/boost/network/protocol/http/message/traits/status.hpp b/boost/network/protocol/http/message/traits/status.hpp index ce1b551a8..92c6c3d6c 100644 --- a/boost/network/protocol/http/message/traits/status.hpp +++ b/boost/network/protocol/http/message/traits/status.hpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace boost { namespace network { @@ -23,7 +24,7 @@ template struct status : mpl::if_< is_async, - std::shared_future, + boost::shared_future, typename mpl::if_, std::uint16_t, unsupported_tag >::type> {}; diff --git a/boost/network/protocol/http/message/traits/status_message.hpp b/boost/network/protocol/http/message/traits/status_message.hpp index 544d55b3f..61b89ec02 100644 --- a/boost/network/protocol/http/message/traits/status_message.hpp +++ b/boost/network/protocol/http/message/traits/status_message.hpp @@ -6,11 +6,11 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include +#include namespace boost { namespace network { @@ -25,7 +25,7 @@ template struct status_message : mpl::if_< is_async, - std::shared_future::type>, + boost::shared_future::type>, typename mpl::if_< mpl::or_, is_same, diff --git a/boost/network/protocol/http/message/traits/version.hpp b/boost/network/protocol/http/message/traits/version.hpp index 103483fcc..3fbcc7348 100644 --- a/boost/network/protocol/http/message/traits/version.hpp +++ b/boost/network/protocol/http/message/traits/version.hpp @@ -6,12 +6,12 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include #include #include +#include namespace boost { namespace network { @@ -30,7 +30,7 @@ struct version { template struct version >::type> { - typedef std::shared_future::type> + typedef boost::shared_future::type> type; }; From db13ac30b51481582f3b339aa8666cb10d3b53ba Mon Sep 17 00:00:00 2001 From: David Mugnai Date: Mon, 19 Sep 2016 00:20:59 +0200 Subject: [PATCH 3/4] docs --- libs/network/doc/reference/http_response.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/network/doc/reference/http_response.rst b/libs/network/doc/reference/http_response.rst index d0a973991..d76bcba28 100644 --- a/libs/network/doc/reference/http_response.rst +++ b/libs/network/doc/reference/http_response.rst @@ -307,3 +307,7 @@ effect: ``template `` *unspecified* ``status_message(basic_response const & response)`` Returns a wrapper convertible to ``typename string::type`` that provides the status message of the given response. +``template `` *unspecified* ``ready(basic_response const & response)`` + Returns a wrapper convertible to ``bool``. The return value is equivalent + to ``true`` if all the response parts have been fetched and it is guaranteed + that a successive call to any wrapper will not block. From 9835d2499fa077381c9c0df16847c63e0ecef060 Mon Sep 17 00:00:00 2001 From: David Mugnai Date: Mon, 19 Sep 2016 20:34:47 +0200 Subject: [PATCH 4/4] trigger travis pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy