From 858eea7b012910007d22b51ee16ed8059eb651b6 Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Mon, 4 Apr 2016 13:22:05 +0200 Subject: [PATCH 001/102] Added image to the license in README.rst. --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 5b8185fb2..8eb2abdd2 100644 --- a/README.rst +++ b/README.rst @@ -9,6 +9,9 @@ Modern C++ network programming libraries. .. image:: https://scan.coverity.com/projects/6714/badge.svg :target: https://scan.coverity.com/projects/cpp-netlib +.. image:: https://img.shields.io/badge/license-boost-blue.svg + :target: https://github.com/cpp-netlib/cpp-netlib/blob/master/LICENSE_1_0.txt + Join us on Slack: http://slack.cpp-netlib.org/ Subscribe to the mailing list: https://groups.google.com/forum/#!forum/cpp-netlib From 0187ec1a064f89c29098a9bb1d8005e87f9bee9a Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sat, 2 Apr 2016 09:30:32 +0200 Subject: [PATCH 002/102] Removed some redundant headers. --- boost/network/include/http/client.hpp | 13 ------------- boost/network/include/http/server.hpp | 13 ------------- boost/network/include/message.hpp | 17 ----------------- libs/network/test/message_transform_test.cpp | 5 ++++- 4 files changed, 4 insertions(+), 44 deletions(-) delete mode 100644 boost/network/include/http/client.hpp delete mode 100644 boost/network/include/http/server.hpp delete mode 100644 boost/network/include/message.hpp diff --git a/boost/network/include/http/client.hpp b/boost/network/include/http/client.hpp deleted file mode 100644 index 3abc042e4..000000000 --- a/boost/network/include/http/client.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef BOOST_NETWORK_INCLUDE_HTTP_CLIENT_HPP_ -#define BOOST_NETWORK_INCLUDE_HTTP_CLIENT_HPP_ - -// Copyright 2009 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) -// -// This is the modular include file for using the HTTP Client - -#include - -#endif // BOOST_NETWORK_INCLUDE_HTTP_CLIENT_HPP_ diff --git a/boost/network/include/http/server.hpp b/boost/network/include/http/server.hpp deleted file mode 100644 index 021eefe0b..000000000 --- a/boost/network/include/http/server.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef BOOST_NETWORK_INCLUDE_HTTP_SERVER_HPP_ -#define BOOST_NETWORK_INCLUDE_HTTP_SERVER_HPP_ - -// 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) -// -// This is the modular include file for using the HTTP Client - -#include - -#endif diff --git a/boost/network/include/message.hpp b/boost/network/include/message.hpp deleted file mode 100644 index 8201ccf77..000000000 --- a/boost/network/include/message.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef BOOST_NETWORK_INCLUDE_MESSAGE_HPP_ -#define BOOST_NETWORK_INCLUDE_MESSAGE_HPP_ - -// Copyright 2009 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) -// -// This is the modular include file for using the basic message type - -#include -#include -#include -#include -#include - -#endif // BOOST_NETWORK_INCLUDE_MESSAGE_HPP_ diff --git a/libs/network/test/message_transform_test.cpp b/libs/network/test/message_transform_test.cpp index 10971519b..2f9abba49 100644 --- a/libs/network/test/message_transform_test.cpp +++ b/libs/network/test/message_transform_test.cpp @@ -7,7 +7,10 @@ #include #include -#include +#include +#include +#include +#include TEST(MessageTransformTest, TransformToUpper) { using namespace boost::network; From 047d89c905dfec56ed6e7dbc5d96afa8ec87c0c0 Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sun, 3 Apr 2016 11:56:57 +0200 Subject: [PATCH 003/102] Added a first test in order to start refactoring the HTTP request/response types. --- .../protocol/http/client/client_request.hpp | 14 +++++ libs/network/test/CMakeLists.txt | 2 +- libs/network/test/http/CMakeLists.txt | 1 + .../test/http/client_constructor_test.cpp | 2 +- .../test/http/http_client_request_test.cpp | 14 +++++ libs/network/test/message_test.cpp | 63 ------------------- libs/network/test/message_transform_test.cpp | 41 ------------ 7 files changed, 31 insertions(+), 106 deletions(-) create mode 100644 boost/network/protocol/http/client/client_request.hpp create mode 100644 libs/network/test/http/http_client_request_test.cpp delete mode 100644 libs/network/test/message_test.cpp delete mode 100644 libs/network/test/message_transform_test.cpp diff --git a/boost/network/protocol/http/client/client_request.hpp b/boost/network/protocol/http/client/client_request.hpp new file mode 100644 index 000000000..6fdccc01c --- /dev/null +++ b/boost/network/protocol/http/client/client_request.hpp @@ -0,0 +1,14 @@ +// Copyright 2016 Glyn Matthews. +// 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 + +namespace boost { +namespace network { +namespace http { +using client_request = basic_request; +} // namespace http +} // namespace network +} // namespace boost diff --git a/libs/network/test/CMakeLists.txt b/libs/network/test/CMakeLists.txt index bbdc3bbf6..0f2dd71bb 100644 --- a/libs/network/test/CMakeLists.txt +++ b/libs/network/test/CMakeLists.txt @@ -10,7 +10,7 @@ add_subdirectory(uri) add_subdirectory(http) if (Boost_FOUND) - set(TESTS message_test message_transform_test utils_thread_pool + set(TESTS utils_thread_pool # utils_base64_test -- turn on when ready. ) foreach (test ${TESTS}) diff --git a/libs/network/test/http/CMakeLists.txt b/libs/network/test/http/CMakeLists.txt index ef7e8b398..f24c3cc4c 100644 --- a/libs/network/test/http/CMakeLists.txt +++ b/libs/network/test/http/CMakeLists.txt @@ -33,6 +33,7 @@ if (Boost_FOUND) ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test}) endforeach (test) set(TESTS + http_client_request_test client_constructor_test client_get_test client_get_different_port_test diff --git a/libs/network/test/http/client_constructor_test.cpp b/libs/network/test/http/client_constructor_test.cpp index 6cd10a1a3..280e64070 100644 --- a/libs/network/test/http/client_constructor_test.cpp +++ b/libs/network/test/http/client_constructor_test.cpp @@ -8,7 +8,7 @@ // Migrated from using Boost.Test to using googletest intead. #include -#include +#include #include "client_types.hpp" namespace http = boost::network::http; diff --git a/libs/network/test/http/http_client_request_test.cpp b/libs/network/test/http/http_client_request_test.cpp new file mode 100644 index 000000000..567053dde --- /dev/null +++ b/libs/network/test/http/http_client_request_test.cpp @@ -0,0 +1,14 @@ +// Copyright 2016 Glyn Matthews. +// 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 + +namespace http = boost::network::http; + +TEST(http_client_request_test, default_construct) +{ + ASSERT_NO_THROW(http::client_request{}); +} diff --git a/libs/network/test/message_test.cpp b/libs/network/test/message_test.cpp deleted file mode 100644 index 2f1140364..000000000 --- a/libs/network/test/message_test.cpp +++ /dev/null @@ -1,63 +0,0 @@ - -// Copyright Dean Michael Berris 2007. -// Copyright 2015 Google, Inc. -// 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) - -// Migrated from using Boost.Test to using googletest instead. -#include -#include -#include -#include -#include - -namespace { - -namespace http = boost::network::http; -namespace network = boost::network; - -template -class MessageTest : public ::testing::Test { -}; - -using TagTypes = ::testing::Types; -TYPED_TEST_CASE(MessageTest, TagTypes); - -TYPED_TEST(MessageTest, Constructors){ - network::basic_message message; // default construction - auto copy = message; // copy construction - ASSERT_TRUE(copy == message); -} - -TYPED_TEST(MessageTest, Equality) { - // Create an original message. - network::basic_message message; - message << network::source("source") << network::destination("destination") - << network::header("key", "value") << network::body("body"); - - // Create the identical message. - network::basic_message other; - other << network::source("source") << network::destination("destination") - << network::header("key", "value") << network::body("body"); - - ASSERT_TRUE(message == other); -} - -TYPED_TEST(MessageTest, Inequality) { - // Create an original message. - network::basic_message message; - message << network::source("source") << network::destination("destination") - << network::header("key", "value") << network::body("body"); - - // Create a different message. - network::basic_message other; - other << network::source("source") << network::destination("destination") - << network::header("key", "value") << network::body("different body!"); - - ASSERT_FALSE(message == other); -} - -} // namespace diff --git a/libs/network/test/message_transform_test.cpp b/libs/network/test/message_transform_test.cpp deleted file mode 100644 index 2f9abba49..000000000 --- a/libs/network/test/message_transform_test.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -// Copyright Dean Michael Berris 2007. -// Copyright 2015, Google, Inc. -// 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 -#include -#include -#include - -TEST(MessageTransformTest, TransformToUpper) { - using namespace boost::network; - - message msg; - msg << source("me"); - ASSERT_EQ("me",source(msg)); - msg << transform(to_upper_, source_); - ASSERT_EQ("ME",source(msg)); - msg << destination("you"); - ASSERT_EQ("you",destination(msg)); - msg << transform(to_upper_, destination_); - ASSERT_EQ("YOU",destination(msg)); -} - -TEST(MessageTransformTest, TransformToLower) { - using namespace boost::network; - - message msg; - msg << source("ME"); - ASSERT_EQ("ME",source(msg)); - msg << transform(to_lower_, source_); - ASSERT_EQ("me",source(msg)); - msg << destination("YOU"); - ASSERT_EQ("YOU",destination(msg)); - msg << transform(to_lower_, destination_); - ASSERT_EQ("you",destination(msg)); -} From 40bab67cd25a833e3a31c1fdbef8f466a083ff67 Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sun, 3 Apr 2016 12:05:16 +0200 Subject: [PATCH 004/102] Since I removed the include directory in a previous commit, I have now updated all the tests. --- libs/network/test/http/client_get_different_port_test.cpp | 2 +- libs/network/test/http/client_get_streaming_test.cpp | 2 +- libs/network/test/http/client_get_test.cpp | 2 +- libs/network/test/http/client_get_timeout_test.cpp | 2 +- libs/network/test/http/client_localhost_normal_test.cpp | 2 +- libs/network/test/http/client_types.hpp | 4 ++-- libs/network/test/http/message_async_ready_test.cpp | 2 +- libs/network/test/http/server_async_run_stop_concurrency.cpp | 2 +- libs/network/test/http/server_constructor_test.cpp | 2 +- libs/network/test/http_server_async_less_copy.cpp | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libs/network/test/http/client_get_different_port_test.cpp b/libs/network/test/http/client_get_different_port_test.cpp index 78e7e7d35..99a524874 100644 --- a/libs/network/test/http/client_get_different_port_test.cpp +++ b/libs/network/test/http/client_get_different_port_test.cpp @@ -6,7 +6,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include #include "client_types.hpp" namespace net = boost::network; diff --git a/libs/network/test/http/client_get_streaming_test.cpp b/libs/network/test/http/client_get_streaming_test.cpp index 0de687c82..9934f6dc5 100644 --- a/libs/network/test/http/client_get_streaming_test.cpp +++ b/libs/network/test/http/client_get_streaming_test.cpp @@ -5,7 +5,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include #include #include "client_types.hpp" diff --git a/libs/network/test/http/client_get_test.cpp b/libs/network/test/http/client_get_test.cpp index b5eb5b77b..75b437e24 100644 --- a/libs/network/test/http/client_get_test.cpp +++ b/libs/network/test/http/client_get_test.cpp @@ -4,7 +4,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include #include "client_types.hpp" namespace net = boost::network; diff --git a/libs/network/test/http/client_get_timeout_test.cpp b/libs/network/test/http/client_get_timeout_test.cpp index 3a22b3fa3..13f60f1c3 100644 --- a/libs/network/test/http/client_get_timeout_test.cpp +++ b/libs/network/test/http/client_get_timeout_test.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include "client_types.hpp" #include "http_test_server.hpp" diff --git a/libs/network/test/http/client_localhost_normal_test.cpp b/libs/network/test/http/client_localhost_normal_test.cpp index 6f965a081..61b91064b 100644 --- a/libs/network/test/http/client_localhost_normal_test.cpp +++ b/libs/network/test/http/client_localhost_normal_test.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libs/network/test/http/client_types.hpp b/libs/network/test/http/client_types.hpp index aa7b1b4fa..dfa25171c 100644 --- a/libs/network/test/http/client_types.hpp +++ b/libs/network/test/http/client_types.hpp @@ -10,7 +10,7 @@ #include #include #include "tag_types.hpp" -#include +#include // HTTPClientTest is a re-usable fixture for client tests that need to test // various variations of the client. This is to be used with googletest's @@ -22,7 +22,7 @@ // // We also already provide ClientTypes as a convenience in this header for all // known and supported client type implementations in the library. -// +// // T must be a tuple in the form: . template class HTTPClientTest : public ::testing::Test { diff --git a/libs/network/test/http/message_async_ready_test.cpp b/libs/network/test/http/message_async_ready_test.cpp index f2b2d9534..67cfcc9c1 100644 --- a/libs/network/test/http/message_async_ready_test.cpp +++ b/libs/network/test/http/message_async_ready_test.cpp @@ -6,7 +6,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include #include "tag_types.hpp" namespace http = boost::network::http; diff --git a/libs/network/test/http/server_async_run_stop_concurrency.cpp b/libs/network/test/http/server_async_run_stop_concurrency.cpp index 10b9e1870..27cc8b118 100644 --- a/libs/network/test/http/server_async_run_stop_concurrency.cpp +++ b/libs/network/test/http/server_async_run_stop_concurrency.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace http = boost::network::http; namespace util = boost::network::utils; diff --git a/libs/network/test/http/server_constructor_test.cpp b/libs/network/test/http/server_constructor_test.cpp index 242be6751..ea38f50b3 100644 --- a/libs/network/test/http/server_constructor_test.cpp +++ b/libs/network/test/http/server_constructor_test.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace http = boost::network::http; namespace util = boost::network::utils; diff --git a/libs/network/test/http_server_async_less_copy.cpp b/libs/network/test/http_server_async_less_copy.cpp index 211ed5e94..a957f05ff 100644 --- a/libs/network/test/http_server_async_less_copy.cpp +++ b/libs/network/test/http_server_async_less_copy.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include From 175cdd3782185eade78b540cb767c5c2ccadae4f Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sun, 3 Apr 2016 12:28:59 +0200 Subject: [PATCH 005/102] Updated the examples that used the include directory that I removed. --- boost/network/utils/thread_group.hpp | 48 +++++-------------- boost/network/utils/thread_pool.hpp | 44 +++++++---------- libs/network/example/http/fileserver.cpp | 2 +- ...llo_world_async_server_with_work_queue.cpp | 2 +- libs/network/example/http/ssl/ssl_server.cpp | 2 +- libs/network/example/trivial_google.cpp | 2 +- 6 files changed, 32 insertions(+), 68 deletions(-) diff --git a/boost/network/utils/thread_group.hpp b/boost/network/utils/thread_group.hpp index 0540b6afb..d1cb62633 100644 --- a/boost/network/utils/thread_group.hpp +++ b/boost/network/utils/thread_group.hpp @@ -9,54 +9,30 @@ #include #include -#include -#include -#include +#include namespace boost { namespace network { namespace utils { class thread_group { - private: - thread_group(thread_group const&); - thread_group& operator=(thread_group const&); - public: - thread_group() {} - ~thread_group() {} + thread_group() = default; + ~thread_group() = default; + thread_group(thread_group const&) = delete; + thread_group& operator=(thread_group const&) = delete; template - std::thread* create_thread(F threadfunc) { - std::lock_guard guard(m); - std::unique_ptr new_thread(new std::thread(threadfunc)); - threads.push_back(std::move(new_thread)); - return threads.back().get(); - } - - void add_thread(std::thread* thrd) { - if (thrd) { - std::lock_guard guard(m); - threads.push_back(std::unique_ptr(thrd)); - } - } - - void remove_thread(std::thread* thrd) { + std::thread &create_thread(F threadfunc) { std::lock_guard guard(m); - auto const it = std::find_if(threads.begin(), threads.end(), - [&thrd] (std::unique_ptr &arg) { - return arg.get() == thrd; - }); - if (it != threads.end()) { - threads.erase(it); - } + threads.emplace_back(threadfunc); + return threads.back(); } void join_all() { std::unique_lock guard(m); - - for (auto &thread : threads) { - if (thread->joinable()) { - thread->join(); + for (auto& thread : threads) { + if (thread.joinable()) { + thread.join(); } } } @@ -67,7 +43,7 @@ class thread_group { } private: - std::list> threads; + std::vector threads; mutable std::mutex m; }; diff --git a/boost/network/utils/thread_pool.hpp b/boost/network/utils/thread_pool.hpp index bea9ab5ad..361bbc1c4 100644 --- a/boost/network/utils/thread_pool.hpp +++ b/boost/network/utils/thread_pool.hpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include @@ -23,18 +21,18 @@ typedef std::shared_ptr io_service_ptr; typedef std::shared_ptr worker_threads_ptr; typedef std::shared_ptr sentinel_ptr; -template -struct basic_thread_pool { - basic_thread_pool(basic_thread_pool const &) = delete; - basic_thread_pool &operator=(basic_thread_pool) = delete; - basic_thread_pool(basic_thread_pool&&) noexcept = default; - basic_thread_pool &operator=(basic_thread_pool&&) = default; +class thread_pool { + public: + thread_pool(thread_pool const &) = delete; + thread_pool &operator=(thread_pool const &) = delete; + thread_pool(thread_pool &&) noexcept = default; + thread_pool &operator=(thread_pool &&) = default; - basic_thread_pool() : basic_thread_pool(1) {} + thread_pool() : thread_pool(1) {} - explicit basic_thread_pool(std::size_t threads, - io_service_ptr io_service = io_service_ptr(), - worker_threads_ptr worker_threads = worker_threads_ptr()) + explicit thread_pool(std::size_t threads, + io_service_ptr io_service = io_service_ptr(), + worker_threads_ptr worker_threads = worker_threads_ptr()) : threads_(threads), io_service_(std::move(io_service)), worker_threads_(std::move(worker_threads)), @@ -46,7 +44,6 @@ struct basic_thread_pool { sentinel_.reset(); io_service_.reset(); if (worker_threads_.get()) { - // worker_threads_->interrupt_all(); worker_threads_->join_all(); } worker_threads_.reset(); @@ -67,7 +64,7 @@ struct basic_thread_pool { } for (std::size_t counter = 0; counter < threads_; ++counter) { - worker_threads_->create_thread([=] () { io_service_->run(); }); + worker_threads_->create_thread([=]() { io_service_->run(); }); } commit = true; @@ -77,18 +74,16 @@ struct basic_thread_pool { void post(std::function f) { io_service_->post(f); } - ~basic_thread_pool() throw() { + ~thread_pool() { sentinel_.reset(); try { worker_threads_->join_all(); - } - catch (...) { - BOOST_ASSERT(false && - "A handler was not supposed to throw, but one did."); + } catch (const std::exception &) { + assert(!"A handler was not supposed to throw, but one did."); } } - void swap(basic_thread_pool &other) { + void swap(thread_pool &other) { using std::swap; swap(other.threads_, threads_); swap(other.io_service_, io_service_); @@ -101,16 +96,9 @@ struct basic_thread_pool { io_service_ptr io_service_; worker_threads_ptr worker_threads_; sentinel_ptr sentinel_; - }; -template -void swap(basic_thread_pool &a, basic_thread_pool &b) { - a.swap(b); -} - -typedef basic_thread_pool thread_pool; - +void swap(thread_pool &a, thread_pool &b) { a.swap(b); } } // namespace utils } // namespace network } // namespace boost diff --git a/libs/network/example/http/fileserver.cpp b/libs/network/example/http/fileserver.cpp index 40ccf7ccf..6c02098cf 100644 --- a/libs/network/example/http/fileserver.cpp +++ b/libs/network/example/http/fileserver.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include diff --git a/libs/network/example/http/hello_world_async_server_with_work_queue.cpp b/libs/network/example/http/hello_world_async_server_with_work_queue.cpp index c2033276e..babde2ad0 100644 --- a/libs/network/example/http/hello_world_async_server_with_work_queue.cpp +++ b/libs/network/example/http/hello_world_async_server_with_work_queue.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libs/network/example/http/ssl/ssl_server.cpp b/libs/network/example/http/ssl/ssl_server.cpp index 9e30eebd1..2208d1263 100644 --- a/libs/network/example/http/ssl/ssl_server.cpp +++ b/libs/network/example/http/ssl/ssl_server.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include diff --git a/libs/network/example/trivial_google.cpp b/libs/network/example/trivial_google.cpp index 800c90b2f..f1722719c 100644 --- a/libs/network/example/trivial_google.cpp +++ b/libs/network/example/trivial_google.cpp @@ -6,7 +6,7 @@ #include -#include +#include namespace http = boost::network::http; From 5614b43a560f5c7bcabb107f983ca13d7f198f87 Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sat, 9 Apr 2016 08:16:07 +0200 Subject: [PATCH 006/102] Removed boost/network.hpp --- boost/network.hpp | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 boost/network.hpp diff --git a/boost/network.hpp b/boost/network.hpp deleted file mode 100644 index 552cbdc82..000000000 --- a/boost/network.hpp +++ /dev/null @@ -1,17 +0,0 @@ - -// Copyright Dean Michael Berris 2007. -// 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) - -#ifndef BOOST_NETWORK_HPP__ -#define BOOST_NETWORK_HPP__ - -// Include all headers in network/ -// Author: Dean Michael Berris -// Date: May 20, 2007 - -#include // message type implementation -#include // protocols implementation - -#endif // BOOST_NETWORK_HPP__ From 2f61e4508579dcc0f10193d71f19e56c84493428 Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sun, 10 Apr 2016 11:48:08 +0200 Subject: [PATCH 007/102] Fixed string constants. --- boost/network/constants.hpp | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/boost/network/constants.hpp b/boost/network/constants.hpp index 3fd3060b8..6af51def6 100644 --- a/boost/network/constants.hpp +++ b/boost/network/constants.hpp @@ -18,80 +18,75 @@ template struct constants_narrow { static char const* crlf() { - static char crlf_[] = {'\r', '\n', 0}; + static char crlf_[] = "\r\n"; return crlf_; } static char const* dot() { - static char dot_[] = {'.', 0}; + static char dot_[] = "."; return dot_; } static char dot_char() { return '.'; } static char const* http_slash() { - static char http_slash_[] = {'H', 'T', 'T', 'P', '/', 0}; + static char http_slash_[] = "HTTP/"; return http_slash_; } static char const* space() { - static char space_[] = {' ', 0}; + static char space_[] = " "; return space_; } static char space_char() { return ' '; } static char const* slash() { - static char slash_[] = {'/', 0}; + static char slash_[] = "/"; return slash_; } static char slash_char() { return '/'; } static char const* host() { - static char host_[] = {'H', 'o', 's', 't', 0}; + static char host_[] = "Host"; return host_; } static char const* colon() { - static char colon_[] = {':', 0}; + static char colon_[] = ":"; return colon_; } static char colon_char() { return ':'; } static char const* accept() { - static char accept_[] = {'A', 'c', 'c', 'e', 'p', 't', 0}; + static char accept_[] = "Accept"; return accept_; } static char const* default_accept_mime() { - static char mime_[] = {'*', '/', '*', 0}; + static char mime_[] = "*/*"; return mime_; } static char const* accept_encoding() { - static char accept_encoding_[] = {'A', 'c', 'c', 'e', 'p', 't', '-', 'E', - 'n', 'c', 'o', 'd', 'i', 'n', 'g', 0}; + static char accept_encoding_[] = "Accept-Encoding"; return accept_encoding_; } static char const* default_accept_encoding() { - static char default_accept_encoding_[] = { - 'i', 'd', 'e', 'n', 't', 'i', 't', 'y', ';', 'q', '=', - '1', '.', '0', ',', ' ', '*', ';', 'q', '=', '0', 0}; + static char default_accept_encoding_[] = "identity;q=1.0, *;q=0"; return default_accept_encoding_; } static char const* user_agent() { - static char user_agent_[] = {'U', 's', 'e', 'r', '-', 'A', - 'g', 'e', 'n', 't', 0}; + static char user_agent_[] = "User-Agent"; return user_agent_; } static char const* cpp_netlib_slash() { - static char cpp_netlib_slash_[] = {'c', 'p', 'p', '-', 'n', 'e', - 't', 'l', 'i', 'b', '/', 0}; + static char cpp_netlib_slash_[] = "cpp-netlib/"; return cpp_netlib_slash_; } @@ -100,13 +95,12 @@ struct constants_narrow { static char hash_char() { return '#'; } static char const* connection() { - static char connection_[] = {'C', 'o', 'n', 'n', 'e', 'c', - 't', 'i', 'o', 'n', 0}; + static char connection_[] = "Connection"; return connection_; } static char const* close() { - static char close_[] = {'C', 'l', 'o', 's', 'e', 0}; + static char close_[] = "Close"; return close_; } From 4c9fbda9e3abe66d64bb397b2eda3b3b202645b8 Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sun, 10 Apr 2016 13:16:44 +0200 Subject: [PATCH 008/102] Added a unit tests for the HTTP client request. --- boost/network/protocol/http/impl/request.hpp | 6 +--- libs/network/test/http/CMakeLists.txt | 2 ++ libs/network/test/http/client/CMakeLists.txt | 28 +++++++++++++++++++ .../network/test/http/client/request_test.cpp | 21 ++++++++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 libs/network/test/http/client/CMakeLists.txt create mode 100644 libs/network/test/http/client/request_test.cpp diff --git a/boost/network/protocol/http/impl/request.hpp b/boost/network/protocol/http/impl/request.hpp index 85ab0f3ae..a94eba099 100644 --- a/boost/network/protocol/http/impl/request.hpp +++ b/boost/network/protocol/http/impl/request.hpp @@ -50,7 +50,7 @@ namespace http { */ template struct basic_request : public basic_message { - mutable boost::network::uri::uri uri_; + boost::network::uri::uri uri_; std::uint16_t source_port_; typedef basic_message base_type; @@ -65,10 +65,6 @@ struct basic_request : public basic_message { explicit basic_request(boost::network::uri::uri const& uri_) : uri_(uri_), source_port_(0) {} - void uri(string_type const& new_uri) { uri_ = new_uri; } - - void uri(boost::network::uri::uri const& new_uri) { uri_ = new_uri; } - basic_request() : base_type(), source_port_(0) {} basic_request(basic_request const& other) diff --git a/libs/network/test/http/CMakeLists.txt b/libs/network/test/http/CMakeLists.txt index f24c3cc4c..a60838229 100644 --- a/libs/network/test/http/CMakeLists.txt +++ b/libs/network/test/http/CMakeLists.txt @@ -12,6 +12,8 @@ if (OPENSSL_FOUND) endif() if (Boost_FOUND) + add_subdirectory(client) + set(TESTS response_incremental_parser_test request_incremental_parser_test request_linearize_test) foreach ( test ${TESTS} ) diff --git a/libs/network/test/http/client/CMakeLists.txt b/libs/network/test/http/client/CMakeLists.txt new file mode 100644 index 000000000..0afab2bb0 --- /dev/null +++ b/libs/network/test/http/client/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright 2016 Glyn Matthews. +# 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) + + +set( + TESTS + request_test + ) + +foreach(test ${TESTS}) + set(test_name cpp-netlib-http-client-${test}) + + add_executable(${test_name} ${test}.cpp) + add_dependencies(${test_name} cppnetlib-uri gtest_main) + target_link_libraries(${test_name} + ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri gtest_main) + set_target_properties(${test_name} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) + add_test(${test_name} + ${CPP-NETLIB_BINARY_DIR}/tests/${test_name}) + + if (OPENSSL_FOUND) + target_link_libraries(${test_name} ${OPENSSL_LIBRARIES}) + endif() + +endforeach(test) diff --git a/libs/network/test/http/client/request_test.cpp b/libs/network/test/http/client/request_test.cpp new file mode 100644 index 000000000..e1b05320d --- /dev/null +++ b/libs/network/test/http/client/request_test.cpp @@ -0,0 +1,21 @@ +// Copyright 2016 Glyn Matthews. +// 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 + + +using client_request = boost::network::http::client::request; + + +TEST(http_client_request, construct_from_uri) { + ASSERT_NO_THROW(client_request("http://cpp-netlib.org/")); +} + +TEST(http_client_request, construct_from_invalid_uri) { + ASSERT_THROW(client_request("I am not a valid URI"), std::exception); +} From 5f6ab563f15417453fb2ba23c8d6f9c03efaa104 Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sun, 10 Apr 2016 15:08:42 +0200 Subject: [PATCH 009/102] Added a unit test for the HTTP client response. --- libs/network/test/http/client/CMakeLists.txt | 1 + libs/network/test/http/client/request_test.cpp | 2 +- libs/network/test/http/client/response_test.cpp | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 libs/network/test/http/client/response_test.cpp diff --git a/libs/network/test/http/client/CMakeLists.txt b/libs/network/test/http/client/CMakeLists.txt index 0afab2bb0..c168cf6e8 100644 --- a/libs/network/test/http/client/CMakeLists.txt +++ b/libs/network/test/http/client/CMakeLists.txt @@ -7,6 +7,7 @@ set( TESTS request_test + response_test ) foreach(test ${TESTS}) diff --git a/libs/network/test/http/client/request_test.cpp b/libs/network/test/http/client/request_test.cpp index e1b05320d..e8d455cc8 100644 --- a/libs/network/test/http/client/request_test.cpp +++ b/libs/network/test/http/client/request_test.cpp @@ -16,6 +16,6 @@ TEST(http_client_request, construct_from_uri) { ASSERT_NO_THROW(client_request("http://cpp-netlib.org/")); } -TEST(http_client_request, construct_from_invalid_uri) { +TEST(http_client_request, DISABLED_construct_from_invalid_uri) { ASSERT_THROW(client_request("I am not a valid URI"), std::exception); } diff --git a/libs/network/test/http/client/response_test.cpp b/libs/network/test/http/client/response_test.cpp new file mode 100644 index 000000000..dd313170b --- /dev/null +++ b/libs/network/test/http/client/response_test.cpp @@ -0,0 +1,17 @@ +// Copyright 2016 Glyn Matthews. +// 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 + + +using client_response = boost::network::http::client::response; + + +TEST(http_client_response, construct) { + ASSERT_NO_THROW(client_response()); +} From 99c777c50172b9ab46726ed61707881b98688e1a Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sun, 10 Apr 2016 15:19:12 +0200 Subject: [PATCH 010/102] Removed some headers that looked redundant. --- .../protocol/http/server/impl/parsers.ipp | 75 ------------------- .../network/protocol/http/server/request.hpp | 51 ------------- .../src/server_request_parsers_impl.cpp | 59 ++++++++++++++- 3 files changed, 55 insertions(+), 130 deletions(-) delete mode 100644 boost/network/protocol/http/server/impl/parsers.ipp delete mode 100644 boost/network/protocol/http/server/request.hpp diff --git a/boost/network/protocol/http/server/impl/parsers.ipp b/boost/network/protocol/http/server/impl/parsers.ipp deleted file mode 100644 index b0de37597..000000000 --- a/boost/network/protocol/http/server/impl/parsers.ipp +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef SERVER_REQUEST_PARSERS_IMPL_UW3PM6V6 -#define SERVER_REQUEST_PARSERS_IMPL_UW3PM6V6 - -#define BOOST_SPIRIT_UNICODE -#include - -// Copyright 2013 Google, Inc. -// 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 - -#ifdef BOOST_NETWORK_NO_LIB -#ifndef BOOST_NETWORK_INLINE -#define BOOST_NETWORK_INLINE inline -#endif -#else -#define BOOST_NETWORK_INLINE -#endif -#include - -namespace boost { -namespace spirit { -namespace traits { - -typedef std::basic_string u32_string; - -template <> // -struct assign_to_container_from_value { - static void call(u32_string const& val, std::string& attr) { - u32_to_u8_iterator begin = val.begin(), - end = val.end(); - for (; begin != end; ++begin) attr += *begin; - } -}; - -} // namespace traits -} // namespace spirit -} // namespace boost - -namespace boost { -namespace network { -namespace http { - -BOOST_NETWORK_INLINE void parse_version( - std::string const& partial_parsed, - std::tuple& version_pair) { - using namespace boost::spirit::qi; - parse(partial_parsed.begin(), partial_parsed.end(), - (lit("HTTP/") >> ushort_ >> '.' >> ushort_), version_pair); -} - -BOOST_NETWORK_INLINE void parse_headers( - std::string const& input, std::vector& container) { - using namespace boost::spirit::qi; - u8_to_u32_iterator begin = input.begin(), - end = input.end(); - typedef as as_u32_string; - parse(begin, end, - *(+((alnum | punct) - ':') >> lit(": ") >> - as_u32_string()[+((unicode::alnum | space | punct) - '\r' - '\n')] >> - lit("\r\n")) >> - lit("\r\n"), - container); -} - -} // namespace http -} // namespace network -} // namespace boost - -#endif /* SERVER_REQUEST_PARSERS_IMPL_UW3PM6V6 */ diff --git a/boost/network/protocol/http/server/request.hpp b/boost/network/protocol/http/server/request.hpp deleted file mode 100644 index f559ebf2d..000000000 --- a/boost/network/protocol/http/server/request.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// -// request.hpp -// ~~~~~~~~~~~ -// -// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com) -// Copyright (c) 2009 Dean Michael Berris (mikhailberis@gmail.com) -// Copyright (c) 2009 Tarro, Inc. -// -// 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) -// - -#ifndef BOOST_NETWORK_HTTP_REQUEST_HPP -#define BOOST_NETWORK_HTTP_REQUEST_HPP - -#include -#include -#include -#include "header.hpp" - -namespace boost { -namespace network { -namespace http { - -/// A request received from a client. -struct request { - std::string method; - std::string uri; - int http_version_major; - int http_version_minor; - std::vector
headers; - std::string body; -}; - -inline void swap(request& l, request& r) { - using std::swap; - swap(l.method, r.method); - swap(l.uri, r.uri); - swap(l.http_version_major, r.http_version_major); - swap(l.http_version_minor, r.http_version_minor); - swap(l.headers, r.headers); - swap(l.body, r.body); -} - -} // namespace http - -} // namespace network - -} // namespace boost - -#endif // BOOST_NETWORK_HTTP_REQUEST_HPP diff --git a/libs/network/src/server_request_parsers_impl.cpp b/libs/network/src/server_request_parsers_impl.cpp index 1b3d4246a..43c0d4721 100644 --- a/libs/network/src/server_request_parsers_impl.cpp +++ b/libs/network/src/server_request_parsers_impl.cpp @@ -1,10 +1,61 @@ +// Copyright 2013 Google, Inc. // 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) -#ifdef BOOST_NETWORK_NO_LIB -#undef BOOST_NETWORK_NO_LIB -#endif +#include +#include +#define BOOST_SPIRIT_UNICODE +#include +#include +#include -#include +namespace boost { +namespace spirit { +namespace traits { + +typedef std::basic_string u32_string; + +template <> // +struct assign_to_container_from_value { + static void call(u32_string const& val, std::string& attr) { + u32_to_u8_iterator begin = val.begin(), + end = val.end(); + for (; begin != end; ++begin) attr += *begin; + } +}; + +} // namespace traits +} // namespace spirit +} // namespace boost + +namespace boost { +namespace network { +namespace http { + +void parse_version( + std::string const& partial_parsed, + std::tuple& version_pair) { + using namespace boost::spirit::qi; + parse(partial_parsed.begin(), partial_parsed.end(), + (lit("HTTP/") >> ushort_ >> '.' >> ushort_), version_pair); +} + +void parse_headers( + std::string const& input, std::vector& container) { + using namespace boost::spirit::qi; + u8_to_u32_iterator begin = input.begin(), + end = input.end(); + typedef as as_u32_string; + parse(begin, end, + *(+((alnum | punct) - ':') >> lit(": ") >> + as_u32_string()[+((unicode::alnum | space | punct) - '\r' - '\n')] >> + lit("\r\n")) >> + lit("\r\n"), + container); +} + +} // namespace http +} // namespace network +} // namespace boost From 1e14f3ceda1da12897a142d0d81307543d78e618 Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Sun, 10 Apr 2016 15:56:44 +0200 Subject: [PATCH 011/102] Refactored HTTP client request and response. --- boost/network/protocol/http/client.hpp | 2 +- boost/network/protocol/http/client/facade.hpp | 10 ++-------- .../{client_request.hpp => request.hpp} | 11 ++++++++--- .../network/protocol/http/client/response.hpp | 19 +++++++++++++++++++ libs/network/test/http/CMakeLists.txt | 1 - .../network/test/http/client/request_test.cpp | 8 ++------ .../test/http/client/response_test.cpp | 8 ++------ .../test/http/http_client_request_test.cpp | 14 -------------- 8 files changed, 34 insertions(+), 39 deletions(-) rename boost/network/protocol/http/client/{client_request.hpp => request.hpp} (60%) create mode 100644 boost/network/protocol/http/client/response.hpp delete mode 100644 libs/network/test/http/http_client_request_test.cpp diff --git a/boost/network/protocol/http/client.hpp b/boost/network/protocol/http/client.hpp index c4d197c16..b0c197658 100644 --- a/boost/network/protocol/http/client.hpp +++ b/boost/network/protocol/http/client.hpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include diff --git a/boost/network/protocol/http/client/facade.hpp b/boost/network/protocol/http/client/facade.hpp index ff05d078b..985344a63 100644 --- a/boost/network/protocol/http/client/facade.hpp +++ b/boost/network/protocol/http/client/facade.hpp @@ -10,19 +10,13 @@ #include #include #include -#include -#include +#include +#include namespace boost { namespace network { namespace http { -template -struct basic_request; - -template -struct basic_response; - template class basic_client_facade { typedef basic_client_impl pimpl_type; diff --git a/boost/network/protocol/http/client/client_request.hpp b/boost/network/protocol/http/client/request.hpp similarity index 60% rename from boost/network/protocol/http/client/client_request.hpp rename to boost/network/protocol/http/client/request.hpp index 6fdccc01c..100970040 100644 --- a/boost/network/protocol/http/client/client_request.hpp +++ b/boost/network/protocol/http/client/request.hpp @@ -3,12 +3,17 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#if !defined(BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_REQUEST_INC) +#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_REQUEST_INC + #include namespace boost { namespace network { namespace http { using client_request = basic_request; -} // namespace http -} // namespace network -} // namespace boost +} // namespace http +} // namespace network +} // namespace boost + +#endif // BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_REQUEST_INC diff --git a/boost/network/protocol/http/client/response.hpp b/boost/network/protocol/http/client/response.hpp new file mode 100644 index 000000000..ca0c9e2e3 --- /dev/null +++ b/boost/network/protocol/http/client/response.hpp @@ -0,0 +1,19 @@ +// Copyright 2016 Glyn Matthews. +// 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) + +#if !defined(BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_RESPONSE_INC) +#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_RESPONSE_INC + +#include + +namespace boost { +namespace network { +namespace http { +using client_response = basic_response; +} // namespace http +} // namespace network +} // namespace boost + +#endif // BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_RESPONSE_INC diff --git a/libs/network/test/http/CMakeLists.txt b/libs/network/test/http/CMakeLists.txt index a60838229..682132e0a 100644 --- a/libs/network/test/http/CMakeLists.txt +++ b/libs/network/test/http/CMakeLists.txt @@ -35,7 +35,6 @@ if (Boost_FOUND) ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test}) endforeach (test) set(TESTS - http_client_request_test client_constructor_test client_get_test client_get_different_port_test diff --git a/libs/network/test/http/client/request_test.cpp b/libs/network/test/http/client/request_test.cpp index e8d455cc8..215e6d1a8 100644 --- a/libs/network/test/http/client/request_test.cpp +++ b/libs/network/test/http/client/request_test.cpp @@ -3,14 +3,10 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) - #include -// #include -#include - - -using client_request = boost::network::http::client::request; +#include +using client_request = boost::network::http::client_request; TEST(http_client_request, construct_from_uri) { ASSERT_NO_THROW(client_request("http://cpp-netlib.org/")); diff --git a/libs/network/test/http/client/response_test.cpp b/libs/network/test/http/client/response_test.cpp index dd313170b..e21917875 100644 --- a/libs/network/test/http/client/response_test.cpp +++ b/libs/network/test/http/client/response_test.cpp @@ -3,14 +3,10 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) - #include -// #include -#include - - -using client_response = boost::network::http::client::response; +#include +using client_response = boost::network::http::client_response; TEST(http_client_response, construct) { ASSERT_NO_THROW(client_response()); diff --git a/libs/network/test/http/http_client_request_test.cpp b/libs/network/test/http/http_client_request_test.cpp deleted file mode 100644 index 567053dde..000000000 --- a/libs/network/test/http/http_client_request_test.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2016 Glyn Matthews. -// 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 - -namespace http = boost::network::http; - -TEST(http_client_request_test, default_construct) -{ - ASSERT_NO_THROW(http::client_request{}); -} From 3bada9438cd2fcb8511e763a7a1607b967ce975c Mon Sep 17 00:00:00 2001 From: Glyn Matthews Date: Tue, 19 Apr 2016 19:31:44 +0200 Subject: [PATCH 012/102] Found every instance of the 'asio' namespace, and qualified them unambiguously. --- .../protocol/http/client/async_impl.hpp | 14 +++---- .../http/client/connection/async_normal.hpp | 42 +++++++++---------- .../connection/async_protocol_handler.hpp | 10 ++--- .../client/connection/connection_delegate.hpp | 6 +-- .../connection_delegate_factory.hpp | 2 +- .../client/connection/normal_delegate.hpp | 12 +++--- .../client/connection/normal_delegate.ipp | 16 +++---- .../http/client/connection/ssl_delegate.hpp | 16 +++---- .../http/client/connection/ssl_delegate.ipp | 36 ++++++++-------- .../http/client/connection/sync_base.hpp | 40 +++++++++--------- .../http/client/connection/sync_normal.hpp | 14 +++---- .../http/client/connection/sync_ssl.hpp | 30 ++++++------- .../network/protocol/http/client/options.hpp | 8 ++-- boost/network/protocol/http/client/pimpl.hpp | 2 +- .../protocol/http/client/sync_impl.hpp | 8 ++-- boost/network/protocol/http/impl/response.ipp | 16 +++---- .../protocol/http/policies/async_resolver.hpp | 4 +- .../http/policies/pooled_connection.hpp | 4 +- .../http/policies/simple_connection.hpp | 2 +- .../protocol/http/server/async_connection.hpp | 38 ++++++++--------- .../protocol/http/server/async_server.hpp | 6 +-- .../network/protocol/http/server/options.hpp | 30 ++++++------- .../http/server/socket_options_base.hpp | 18 ++++---- .../protocol/http/server/storage_base.hpp | 6 +-- .../network/protocol/http/traits/resolver.hpp | 4 +- boost/network/protocol/stream_handler.hpp | 12 +++--- boost/network/uri/builder.hpp | 12 +++--- boost/network/utils/thread_pool.hpp | 8 ++-- 28 files changed, 208 insertions(+), 208 deletions(-) diff --git a/boost/network/protocol/http/client/async_impl.hpp b/boost/network/protocol/http/client/async_impl.hpp index bb4eab191..fb1dc5079 100644 --- a/boost/network/protocol/http/client/async_impl.hpp +++ b/boost/network/protocol/http/client/async_impl.hpp @@ -39,7 +39,7 @@ struct async_client async_client(bool cache_resolved, bool follow_redirect, bool always_verify_peer, int timeout, - std::shared_ptr service, + std::shared_ptr<::asio::io_service> service, optional certificate_filename, optional verify_path, optional certificate_file, @@ -48,10 +48,10 @@ struct async_client optional sni_hostname, long ssl_options) : connection_base(cache_resolved, follow_redirect, timeout), service_ptr(service.get() ? service - : std::make_shared()), + : std::make_shared<::asio::io_service>()), service_(*service_ptr), resolver_(service_), - sentinel_(new asio::io_service::work(service_)), + sentinel_(new ::asio::io_service::work(service_)), certificate_filename_(std::move(certificate_filename)), verify_path_(std::move(verify_path)), certificate_file_(std::move(certificate_file)), @@ -61,7 +61,7 @@ struct async_client ssl_options_(ssl_options), always_verify_peer_(always_verify_peer) { connection_base::resolver_strand_.reset( - new asio::io_service::strand(service_)); + new ::asio::io_service::strand(service_)); if (!service) lifetime_thread_.reset(new std::thread([this]() { service_.run(); })); } @@ -89,10 +89,10 @@ struct async_client generator); } - std::shared_ptr service_ptr; - asio::io_service& service_; + std::shared_ptr<::asio::io_service> service_ptr; + ::asio::io_service& service_; resolver_type resolver_; - std::shared_ptr sentinel_; + std::shared_ptr<::asio::io_service::work> sentinel_; std::shared_ptr lifetime_thread_; optional certificate_filename_; optional verify_path_; diff --git a/boost/network/protocol/http/client/connection/async_normal.hpp b/boost/network/protocol/http/client/connection/async_normal.hpp index 1604a727e..35c12b365 100644 --- a/boost/network/protocol/http/client/connection/async_normal.hpp +++ b/boost/network/protocol/http/client/connection/async_normal.hpp @@ -40,7 +40,7 @@ namespace impl { template struct async_connection_base; -namespace placeholders = asio::placeholders; +namespace placeholders = ::asio::placeholders; template struct http_async_connection @@ -145,7 +145,7 @@ struct http_async_connection // Here we deal with the case that there was an error encountered and // that there's still more endpoints to try connecting to. resolver_iterator iter = boost::begin(endpoint_range); - asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); + ::asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); auto self = this->shared_from_this(); delegate_->connect( endpoint, host, source_port, @@ -155,7 +155,7 @@ struct http_async_connection generator, std::make_pair(++iter_copy, resolver_iterator()), ec); })); } else { - set_errors(ec ? ec : asio::error::host_not_found); + set_errors(ec ? ec : ::asio::error::host_not_found); boost::iterator_range range; if (callback) callback(range, ec); } @@ -168,7 +168,7 @@ struct http_async_connection resolver_iterator_pair endpoint_range, std::error_code const& ec) { if (is_timedout_) { - set_errors(asio::error::timed_out); + set_errors(::asio::error::timed_out); } else if (!ec) { BOOST_ASSERT(delegate_.get() != 0); auto self = this->shared_from_this(); @@ -182,7 +182,7 @@ struct http_async_connection } else { if (!boost::empty(endpoint_range)) { resolver_iterator iter = boost::begin(endpoint_range); - asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); + ::asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); auto self = this->shared_from_this(); delegate_->connect( endpoint, host, source_port, @@ -193,7 +193,7 @@ struct http_async_connection ec); })); } else { - set_errors(ec ? ec : asio::error::host_not_found); + set_errors(ec ? ec : ::asio::error::host_not_found); boost::iterator_range range; if (callback) callback(range, ec); } @@ -231,7 +231,7 @@ struct http_async_connection auto self = this->shared_from_this(); delegate_->read_some( - asio::mutable_buffers_1(this->part.data(), + ::asio::mutable_buffers_1(this->part.data(), this->part.size()), request_strand_.wrap([=] (std::error_code const &ec, std::size_t bytes_transferred) { @@ -239,7 +239,7 @@ struct http_async_connection ec, bytes_transferred); })); } else { - set_errors(is_timedout_ ? asio::error::timed_out : ec); + set_errors(is_timedout_ ? ::asio::error::timed_out : ec); } } @@ -250,19 +250,19 @@ struct http_async_connection static const long short_read_error = 335544539; bool is_ssl_short_read_error = #ifdef BOOST_NETWORK_ENABLE_HTTPS - ec.category() == asio::error::ssl_category && + ec.category() == ::asio::error::ssl_category && ec.value() == short_read_error; #else false && short_read_error; #endif if (!is_timedout_ && - (!ec || ec == asio::error::eof || is_ssl_short_read_error)) { + (!ec || ec == ::asio::error::eof || is_ssl_short_read_error)) { logic::tribool parsed_ok; size_t remainder; auto self = this->shared_from_this(); switch (state) { case version: - if (ec == asio::error::eof) return; + if (ec == ::asio::error::eof) return; parsed_ok = this->parse_version( delegate_, request_strand_.wrap([=] (std::error_code const &ec, @@ -275,7 +275,7 @@ struct http_async_connection return; } case status: - if (ec == asio::error::eof) return; + if (ec == ::asio::error::eof) return; parsed_ok = this->parse_status( delegate_, request_strand_.wrap([=] (std::error_code const &ec, @@ -288,7 +288,7 @@ struct http_async_connection return; } case status_message: - if (ec == asio::error::eof) return; + if (ec == ::asio::error::eof) return; parsed_ok = this->parse_status_message( delegate_, request_strand_.wrap([=] (std::error_code const &, std::size_t bytes_transferred) { @@ -300,7 +300,7 @@ struct http_async_connection return; } case headers: - if (ec == asio::error::eof) return; + if (ec == ::asio::error::eof) return; // In the following, remainder is the number of bytes that remain in // the buffer. We need this in the body processing to make sure that // the data remaining in the buffer is dealt with before another call @@ -352,7 +352,7 @@ struct http_async_connection auto self = this->shared_from_this(); delegate_->read_some( - asio::mutable_buffers_1(this->part.data(), + ::asio::mutable_buffers_1(this->part.data(), this->part.size()), request_strand_.wrap([=] (std::error_code const &ec, std::size_t bytes_transferred) { @@ -374,7 +374,7 @@ struct http_async_connection } return; case body: - if (ec == asio::error::eof || is_ssl_short_read_error) { + if (ec == ::asio::error::eof || is_ssl_short_read_error) { // Here we're handling the case when the connection has been closed // from the server side, or at least that the end of file has been // reached while reading the socket. This signals the end of the @@ -420,7 +420,7 @@ struct http_async_connection callback(make_iterator_range(begin, end), ec); auto self = this->shared_from_this(); delegate_->read_some( - asio::mutable_buffers_1(this->part.data(), + ::asio::mutable_buffers_1(this->part.data(), this->part.size()), request_strand_.wrap([=] (std::error_code const &ec, std::size_t bytes_transferred) { @@ -446,7 +446,7 @@ struct http_async_connection BOOST_ASSERT(false && "Bug, report this to the developers!"); } } else { - std::system_error error(is_timedout_ ? asio::error::timed_out + std::system_error error(is_timedout_ ? ::asio::error::timed_out : ec); this->source_promise.set_exception(std::make_exception_ptr(error)); this->destination_promise.set_exception(std::make_exception_ptr(error)); @@ -506,14 +506,14 @@ struct http_async_connection } int timeout_; - asio::deadline_timer timer_; + ::asio::deadline_timer timer_; bool is_timedout_; bool follow_redirect_; resolver_type& resolver_; resolve_function resolve_; - asio::io_service::strand request_strand_; + ::asio::io_service::strand request_strand_; connection_delegate_ptr delegate_; - asio::streambuf command_streambuf; + ::asio::streambuf command_streambuf; string_type method; }; diff --git a/boost/network/protocol/http/client/connection/async_protocol_handler.hpp b/boost/network/protocol/http/client/connection/async_protocol_handler.hpp index a860efb61..b35086206 100644 --- a/boost/network/protocol/http/client/connection/async_protocol_handler.hpp +++ b/boost/network/protocol/http/client/connection/async_protocol_handler.hpp @@ -139,7 +139,7 @@ struct http_async_protocol_handler { std::end(result_range)); part_begin = part.begin(); delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), + ::asio::mutable_buffers_1(part.data(), part.size()), callback); } return parsed_ok; @@ -185,7 +185,7 @@ struct http_async_protocol_handler { std::end(result_range)); part_begin = part.begin(); delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), + ::asio::mutable_buffers_1(part.data(), part.size()), callback); } return parsed_ok; @@ -230,7 +230,7 @@ struct http_async_protocol_handler { std::end(result_range)); part_begin = part.begin(); delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), + ::asio::mutable_buffers_1(part.data(), part.size()), callback); } return parsed_ok; @@ -317,7 +317,7 @@ struct http_async_protocol_handler { std::end(result_range)); part_begin = part.begin(); delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), + ::asio::mutable_buffers_1(part.data(), part.size()), callback); } return std::make_tuple( @@ -331,7 +331,7 @@ struct http_async_protocol_handler { partial_parsed.append(part_begin, bytes); part_begin = part.begin(); delegate_->read_some( - asio::mutable_buffers_1(part.data(), part.size()), callback); + ::asio::mutable_buffers_1(part.data(), part.size()), callback); } typedef response_parser response_parser_type; diff --git a/boost/network/protocol/http/client/connection/connection_delegate.hpp b/boost/network/protocol/http/client/connection/connection_delegate.hpp index fb18a04a1..c3a2f2acb 100644 --- a/boost/network/protocol/http/client/connection/connection_delegate.hpp +++ b/boost/network/protocol/http/client/connection/connection_delegate.hpp @@ -18,14 +18,14 @@ namespace http { namespace impl { struct connection_delegate { - virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host, + virtual void connect(::asio::ip::tcp::endpoint &endpoint, std::string host, std::uint16_t source_port, std::function handler) = 0; virtual void write( - asio::streambuf &command_streambuf, + ::asio::streambuf &command_streambuf, std::function handler) = 0; virtual void read_some( - asio::mutable_buffers_1 const &read_buffer, + ::asio::mutable_buffers_1 const &read_buffer, std::function handler) = 0; virtual void disconnect() = 0; virtual ~connection_delegate() = default; diff --git a/boost/network/protocol/http/client/connection/connection_delegate_factory.hpp b/boost/network/protocol/http/client/connection/connection_delegate_factory.hpp index 7a78002e5..f2b17e57e 100644 --- a/boost/network/protocol/http/client/connection/connection_delegate_factory.hpp +++ b/boost/network/protocol/http/client/connection/connection_delegate_factory.hpp @@ -34,7 +34,7 @@ struct connection_delegate_factory { // This is the factory method that actually returns the delegate instance. // TODO(dberris): Support passing in proxy settings when crafting connections. static connection_delegate_ptr new_connection_delegate( - asio::io_service& service, bool https, bool always_verify_peer, + ::asio::io_service& service, bool https, bool always_verify_peer, optional certificate_filename, optional verify_path, optional certificate_file, optional private_key_file, optional ciphers, diff --git a/boost/network/protocol/http/client/connection/normal_delegate.hpp b/boost/network/protocol/http/client/connection/normal_delegate.hpp index eb8b43a69..daa711299 100644 --- a/boost/network/protocol/http/client/connection/normal_delegate.hpp +++ b/boost/network/protocol/http/client/connection/normal_delegate.hpp @@ -22,15 +22,15 @@ namespace http { namespace impl { struct normal_delegate : connection_delegate { - explicit normal_delegate(asio::io_service &service); + explicit normal_delegate(::asio::io_service &service); - void connect(asio::ip::tcp::endpoint &endpoint, std::string host, + void connect(::asio::ip::tcp::endpoint &endpoint, std::string host, std::uint16_t source_port, std::function handler) override; - void write(asio::streambuf &command_streambuf, + void write(::asio::streambuf &command_streambuf, std::function handler) override; - void read_some(asio::mutable_buffers_1 const &read_buffer, + void read_some(::asio::mutable_buffers_1 const &read_buffer, std::function handler) override; void disconnect() override; @@ -40,8 +40,8 @@ struct normal_delegate : connection_delegate { normal_delegate &operator=(normal_delegate) = delete; private: - asio::io_service &service_; - std::unique_ptr socket_; + ::asio::io_service &service_; + std::unique_ptr<::asio::ip::tcp::socket> socket_; }; } // namespace impl diff --git a/boost/network/protocol/http/client/connection/normal_delegate.ipp b/boost/network/protocol/http/client/connection/normal_delegate.ipp index 091313c99..78f529263 100644 --- a/boost/network/protocol/http/client/connection/normal_delegate.ipp +++ b/boost/network/protocol/http/client/connection/normal_delegate.ipp @@ -16,31 +16,31 @@ #include boost::network::http::impl::normal_delegate::normal_delegate( - asio::io_service &service) + ::asio::io_service &service) : service_(service) {} void boost::network::http::impl::normal_delegate::connect( - asio::ip::tcp::endpoint &endpoint, std::string host, + ::asio::ip::tcp::endpoint &endpoint, std::string host, std::uint16_t source_port, std::function handler) { // TODO(dberris): review parameter necessity. (void)host; - socket_.reset(new asio::ip::tcp::socket( + socket_.reset(new ::asio::ip::tcp::socket( service_, - asio::ip::tcp::endpoint(asio::ip::address(), source_port))); + ::asio::ip::tcp::endpoint(::asio::ip::address(), source_port))); socket_->async_connect(endpoint, handler); } void boost::network::http::impl::normal_delegate::write( - asio::streambuf &command_streambuf, + ::asio::streambuf &command_streambuf, std::function handler) { - asio::async_write(*socket_, command_streambuf, handler); + ::asio::async_write(*socket_, command_streambuf, handler); } void boost::network::http::impl::normal_delegate::read_some( - asio::mutable_buffers_1 const &read_buffer, + ::asio::mutable_buffers_1 const &read_buffer, std::function handler) { socket_->async_read_some(read_buffer, handler); } @@ -48,7 +48,7 @@ void boost::network::http::impl::normal_delegate::read_some( void boost::network::http::impl::normal_delegate::disconnect() { if (socket_.get() && socket_->is_open()) { std::error_code ignored; - socket_->shutdown(asio::ip::tcp::socket::shutdown_both, ignored); + socket_->shutdown(::asio::ip::tcp::socket::shutdown_both, ignored); if (!ignored) { socket_->close(ignored); } diff --git a/boost/network/protocol/http/client/connection/ssl_delegate.hpp b/boost/network/protocol/http/client/connection/ssl_delegate.hpp index 0916af235..d6fcee3fe 100644 --- a/boost/network/protocol/http/client/connection/ssl_delegate.hpp +++ b/boost/network/protocol/http/client/connection/ssl_delegate.hpp @@ -24,7 +24,7 @@ namespace impl { struct ssl_delegate : public connection_delegate, public std::enable_shared_from_this { - ssl_delegate(asio::io_service &service, bool always_verify_peer, + ssl_delegate(::asio::io_service &service, bool always_verify_peer, optional certificate_filename, optional verify_path, optional certificate_file, @@ -32,20 +32,20 @@ struct ssl_delegate : public connection_delegate, optional ciphers, optional sni_hostname, long ssl_options); - void connect(asio::ip::tcp::endpoint &endpoint, std::string host, + void connect(::asio::ip::tcp::endpoint &endpoint, std::string host, std::uint16_t source_port, std::function handler) override; void write( - asio::streambuf &command_streambuf, + ::asio::streambuf &command_streambuf, std::function handler) override; void read_some( - asio::mutable_buffers_1 const &read_buffer, + ::asio::mutable_buffers_1 const &read_buffer, std::function handler) override; void disconnect() override; ~ssl_delegate() override; private: - asio::io_service &service_; + ::asio::io_service &service_; optional certificate_filename_; optional verify_path_; optional certificate_file_; @@ -53,9 +53,9 @@ struct ssl_delegate : public connection_delegate, optional ciphers_; optional sni_hostname_; long ssl_options_; - std::unique_ptr context_; - std::unique_ptr tcp_socket_; - std::unique_ptr > socket_; + std::unique_ptr<::asio::ssl::context> context_; + std::unique_ptr<::asio::ip::tcp::socket> tcp_socket_; + std::unique_ptr<::asio::ssl::stream<::asio::ip::tcp::socket &> > socket_; bool always_verify_peer_; ssl_delegate(ssl_delegate const &); // = delete diff --git a/boost/network/protocol/http/client/connection/ssl_delegate.ipp b/boost/network/protocol/http/client/connection/ssl_delegate.ipp index b303a24de..f3b179d01 100644 --- a/boost/network/protocol/http/client/connection/ssl_delegate.ipp +++ b/boost/network/protocol/http/client/connection/ssl_delegate.ipp @@ -13,7 +13,7 @@ #include boost::network::http::impl::ssl_delegate::ssl_delegate( - asio::io_service &service, bool always_verify_peer, + ::asio::io_service &service, bool always_verify_peer, optional certificate_filename, optional verify_path, optional certificate_file, optional private_key_file, optional ciphers, @@ -29,11 +29,11 @@ boost::network::http::impl::ssl_delegate::ssl_delegate( always_verify_peer_(always_verify_peer) {} void boost::network::http::impl::ssl_delegate::connect( - asio::ip::tcp::endpoint &endpoint, std::string host, + ::asio::ip::tcp::endpoint &endpoint, std::string host, std::uint16_t source_port, std::function handler) { context_.reset( - new asio::ssl::context(asio::ssl::context::method::sslv23_client)); + new ::asio::ssl::context(::asio::ssl::context::method::sslv23_client)); if (ciphers_) { ::SSL_CTX_set_cipher_list(context_->native_handle(), ciphers_->c_str()); } @@ -41,37 +41,37 @@ void boost::network::http::impl::ssl_delegate::connect( context_->set_options(ssl_options_); } else { // By default, disable v3 support. - context_->set_options(asio::ssl::context::no_sslv3); + context_->set_options(::asio::ssl::context::no_sslv3); } if (certificate_filename_ || verify_path_) { - context_->set_verify_mode(asio::ssl::context::verify_peer); + context_->set_verify_mode(::asio::ssl::context::verify_peer); if (certificate_filename_) context_->load_verify_file(*certificate_filename_); if (verify_path_) context_->add_verify_path(*verify_path_); } else { if (always_verify_peer_) { - context_->set_verify_mode(asio::ssl::context::verify_peer); + context_->set_verify_mode(::asio::ssl::context::verify_peer); // use openssl default verify paths. uses openssl environment variables // SSL_CERT_DIR, SSL_CERT_FILE context_->set_default_verify_paths(); } else { - context_->set_verify_mode(asio::ssl::context::verify_none); + context_->set_verify_mode(::asio::ssl::context::verify_none); } } if (certificate_file_) - context_->use_certificate_file(*certificate_file_, asio::ssl::context::pem); + context_->use_certificate_file(*certificate_file_, ::asio::ssl::context::pem); if (private_key_file_) - context_->use_private_key_file(*private_key_file_, asio::ssl::context::pem); + context_->use_private_key_file(*private_key_file_, ::asio::ssl::context::pem); - tcp_socket_.reset(new asio::ip::tcp::socket( - service_, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), source_port))); - socket_.reset(new asio::ssl::stream( + tcp_socket_.reset(new ::asio::ip::tcp::socket( + service_, ::asio::ip::tcp::endpoint(::asio::ip::tcp::v4(), source_port))); + socket_.reset(new ::asio::ssl::stream<::asio::ip::tcp::socket &>( *(tcp_socket_.get()), *context_)); if (sni_hostname_) SSL_set_tlsext_host_name(socket_->native_handle(), sni_hostname_->c_str()); if (always_verify_peer_) - socket_->set_verify_callback(asio::ssl::rfc2818_verification(host)); + socket_->set_verify_callback(::asio::ssl::rfc2818_verification(host)); auto self = this->shared_from_this(); socket_->lowest_layer().async_connect( endpoint, @@ -82,20 +82,20 @@ void boost::network::http::impl::ssl_delegate::handle_connected( std::error_code const &ec, std::function handler) { if (!ec) { - socket_->async_handshake(asio::ssl::stream_base::client, handler); + socket_->async_handshake(::asio::ssl::stream_base::client, handler); } else { handler(ec); } } void boost::network::http::impl::ssl_delegate::write( - asio::streambuf &command_streambuf, + ::asio::streambuf &command_streambuf, std::function handler) { - asio::async_write(*socket_, command_streambuf, handler); + ::asio::async_write(*socket_, command_streambuf, handler); } void boost::network::http::impl::ssl_delegate::read_some( - asio::mutable_buffers_1 const &read_buffer, + ::asio::mutable_buffers_1 const &read_buffer, std::function handler) { socket_->async_read_some(read_buffer, handler); } @@ -103,7 +103,7 @@ void boost::network::http::impl::ssl_delegate::read_some( void boost::network::http::impl::ssl_delegate::disconnect() { if (socket_.get() && socket_->lowest_layer().is_open()) { std::error_code ignored; - socket_->lowest_layer().shutdown(asio::ip::tcp::socket::shutdown_both, + socket_->lowest_layer().shutdown(::asio::ip::tcp::socket::shutdown_both, ignored); if (!ignored) { socket_->lowest_layer().close(ignored); diff --git a/boost/network/protocol/http/client/connection/sync_base.hpp b/boost/network/protocol/http/client/connection/sync_base.hpp index 4d940c334..4cf9abeba 100644 --- a/boost/network/protocol/http/client/connection/sync_base.hpp +++ b/boost/network/protocol/http/client/connection/sync_base.hpp @@ -41,8 +41,8 @@ struct sync_connection_base_impl { void init_socket(Socket& socket_, resolver_type& resolver_, string_type /*unused*/ const& hostname, string_type const& port, resolver_function_type resolve_) { - using asio::ip::tcp; - std::error_code error = asio::error::host_not_found; + using ::asio::ip::tcp; + std::error_code error = ::asio::error::host_not_found; typename resolver_type::iterator endpoint_iterator, end; boost::tie(endpoint_iterator, end) = resolve_(resolver_, hostname, port); while (error && endpoint_iterator != end) { @@ -58,8 +58,8 @@ struct sync_connection_base_impl { template void read_status(Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer) { - asio::read_until(socket_, response_buffer, "\r\n"); + ::asio::streambuf& response_buffer) { + ::asio::read_until(socket_, response_buffer, "\r\n"); std::istream response_stream(&response_buffer); string_type http_version; unsigned int status_code; @@ -78,8 +78,8 @@ struct sync_connection_base_impl { template void read_headers(Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer) { - asio::read_until(socket_, response_buffer, "\r\n\r\n"); + ::asio::streambuf& response_buffer) { + ::asio::read_until(socket_, response_buffer, "\r\n\r\n"); std::istream response_stream(&response_buffer); string_type header_line, name; while (std::getline(response_stream, header_line) && header_line != "\r") { @@ -101,7 +101,7 @@ struct sync_connection_base_impl { template void send_request_impl(Socket& socket_, string_type /*unused*/ const& method, - asio::streambuf& request_buffer) { + ::asio::streambuf& request_buffer) { // TODO(dberris): review parameter necessity. (void)method; @@ -110,7 +110,7 @@ struct sync_connection_base_impl { template void read_body_normal(Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer, + ::asio::streambuf& response_buffer, typename ostringstream::type& body_stream) { // TODO(dberris): review parameter necessity. (void)response_; @@ -118,7 +118,7 @@ struct sync_connection_base_impl { std::error_code error; if (response_buffer.size() > 0) body_stream << &response_buffer; - while (asio::read(socket_, response_buffer, asio::transfer_at_least(1), + while (::asio::read(socket_, response_buffer, ::asio::transfer_at_least(1), error)) { body_stream << &response_buffer; } @@ -127,7 +127,7 @@ struct sync_connection_base_impl { template void read_body_transfer_chunk_encoding( Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer, + ::asio::streambuf& response_buffer, typename ostringstream::type& body_stream) { std::error_code error; // look for the content-length header @@ -146,7 +146,7 @@ struct sync_connection_base_impl { do { std::size_t chunk_size_line = read_until(socket_, response_buffer, "\r\n", error); - if ((chunk_size_line == 0) && (error != asio::error::eof)) + if ((chunk_size_line == 0) && (error != ::asio::error::eof)) throw std::system_error(error); std::size_t chunk_size = 0; string_type data; @@ -159,7 +159,7 @@ struct sync_connection_base_impl { if (chunk_size == 0) { stopping = true; if (!read_until(socket_, response_buffer, "\r\n", error) && - (error != asio::error::eof)) + (error != ::asio::error::eof)) throw std::system_error(error); } else { bool stopping_inner = false; @@ -169,9 +169,9 @@ struct sync_connection_base_impl { (chunk_size + 2) - response_buffer.size(); std::size_t chunk_bytes_read = read(socket_, response_buffer, - asio::transfer_at_least(bytes_to_read), error); + ::asio::transfer_at_least(bytes_to_read), error); if (chunk_bytes_read == 0) { - if (error != asio::error::eof) throw std::system_error(error); + if (error != ::asio::error::eof) throw std::system_error(error); stopping_inner = true; } } @@ -200,8 +200,8 @@ struct sync_connection_base_impl { return; } size_t bytes_read = 0; - while ((bytes_read = asio::read(socket_, response_buffer, - asio::transfer_at_least(1), error))) { + while ((bytes_read = ::asio::read(socket_, response_buffer, + ::asio::transfer_at_least(1), error))) { body_stream << &response_buffer; length -= bytes_read; if ((length <= 0) || error) break; @@ -211,7 +211,7 @@ struct sync_connection_base_impl { template void read_body(Socket& socket_, basic_response& response_, - asio::streambuf& response_buffer) { + ::asio::streambuf& response_buffer) { typename ostringstream::type body_stream; // TODO(dberris): tag dispatch based on whether it's HTTP 1.0 or HTTP 1.1 if (version_major == 1 && version_minor == 0) { @@ -282,11 +282,11 @@ struct sync_connection_base { basic_request const& request_, body_generator_function_type generator) = 0; virtual void read_status(basic_response& response_, - asio::streambuf& response_buffer) = 0; + ::asio::streambuf& response_buffer) = 0; virtual void read_headers(basic_response& response_, - asio::streambuf& response_buffer) = 0; + ::asio::streambuf& response_buffer) = 0; virtual void read_body(basic_response& response_, - asio::streambuf& response_buffer) = 0; + ::asio::streambuf& response_buffer) = 0; virtual bool is_open() = 0; virtual void close_socket() = 0; virtual ~sync_connection_base() = default; diff --git a/boost/network/protocol/http/client/connection/sync_normal.hpp b/boost/network/protocol/http/client/connection/sync_normal.hpp index 27e1e1cc6..0d252766b 100644 --- a/boost/network/protocol/http/client/connection/sync_normal.hpp +++ b/boost/network/protocol/http/client/connection/sync_normal.hpp @@ -61,7 +61,7 @@ struct http_sync_connection void send_request_impl(string_type const& method, basic_request const& request_, body_generator_function_type generator) { - asio::streambuf request_buffer; + ::asio::streambuf request_buffer; linearize( request_, method, version_major, version_minor, std::ostreambuf_iterator::type>(&request_buffer)); @@ -86,17 +86,17 @@ struct http_sync_connection } void read_status(basic_response& response_, - asio::streambuf& response_buffer) { + ::asio::streambuf& response_buffer) { connection_base::read_status(socket_, response_, response_buffer); } void read_headers(basic_response& response, - asio::streambuf& response_buffer) { + ::asio::streambuf& response_buffer) { connection_base::read_headers(socket_, response, response_buffer); } void read_body(basic_response& response_, - asio::streambuf& response_buffer) { + ::asio::streambuf& response_buffer) { connection_base::read_body(socket_, response_, response_buffer); typename headers_range >::type connection_range = headers(response_)["Connection"]; @@ -117,7 +117,7 @@ struct http_sync_connection return; } std::error_code ignored; - socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ignored); + socket_.shutdown(::asio::ip::tcp::socket::shutdown_both, ignored); if (ignored) { return; } @@ -132,10 +132,10 @@ struct http_sync_connection } int timeout_; - asio::deadline_timer timer_; + ::asio::deadline_timer timer_; resolver_type& resolver_; resolver_function_type resolve_; - asio::ip::tcp::socket socket_; + ::asio::ip::tcp::socket socket_; }; } // namespace impl diff --git a/boost/network/protocol/http/client/connection/sync_ssl.hpp b/boost/network/protocol/http/client/connection/sync_ssl.hpp index d973fc0d6..f115066a7 100644 --- a/boost/network/protocol/http/client/connection/sync_ssl.hpp +++ b/boost/network/protocol/http/client/connection/sync_ssl.hpp @@ -63,7 +63,7 @@ struct https_sync_connection timer_(resolver.get_io_service()), resolver_(resolver), resolve_(std::move(resolve)), - context_(resolver.get_io_service(), asio::ssl::context::sslv23_client), + context_(resolver.get_io_service(), ::asio::ssl::context::sslv23_client), socket_(resolver.get_io_service(), context_) { if (ciphers) { ::SSL_CTX_set_cipher_list(context_.native_handle(), ciphers->c_str()); @@ -72,7 +72,7 @@ struct https_sync_connection context_.set_options(ssl_options); } if (certificate_filename || verify_path) { - context_.set_verify_mode(asio::ssl::context::verify_peer); + context_.set_verify_mode(::asio::ssl::context::verify_peer); // FIXME make the certificate filename and verify path parameters // be // optional ranges @@ -81,14 +81,14 @@ struct https_sync_connection if (verify_path) context_.add_verify_path(*verify_path); } else { if (always_verify_peer) - context_.set_verify_mode(asio::ssl::context_base::verify_peer); + context_.set_verify_mode(::asio::ssl::context_base::verify_peer); else - context_.set_verify_mode(asio::ssl::context_base::verify_none); + context_.set_verify_mode(::asio::ssl::context_base::verify_none); } if (certificate_file) - context_.use_certificate_file(*certificate_file, asio::ssl::context::pem); + context_.use_certificate_file(*certificate_file, ::asio::ssl::context::pem); if (private_key_file) - context_.use_private_key_file(*private_key_file, asio::ssl::context::pem); + context_.use_private_key_file(*private_key_file, ::asio::ssl::context::pem); if (sni_hostname) SSL_set_tlsext_host_name(socket_.native_handle(), sni_hostname->c_str()); } @@ -97,13 +97,13 @@ struct https_sync_connection string_type const& port) { connection_base::init_socket(socket_.lowest_layer(), resolver_, hostname, port, resolve_); - socket_.handshake(asio::ssl::stream_base::client); + socket_.handshake(::asio::ssl::stream_base::client); } void send_request_impl(string_type /*unused*/ const& method, basic_request const& request_, body_generator_function_type generator) { - asio::streambuf request_buffer; + ::asio::streambuf request_buffer; linearize( request_, method, version_major, version_minor, std::ostreambuf_iterator::type>(&request_buffer)); @@ -127,17 +127,17 @@ struct https_sync_connection } void read_status(basic_response& response_, - asio::streambuf& response_buffer) { + ::asio::streambuf& response_buffer) { connection_base::read_status(socket_, response_, response_buffer); } void read_headers(basic_response& response_, - asio::streambuf& response_buffer) { + ::asio::streambuf& response_buffer) { connection_base::read_headers(socket_, response_, response_buffer); } void read_body(basic_response& response_, - asio::streambuf& response_buffer) { + ::asio::streambuf& response_buffer) { connection_base::read_body(socket_, response_, response_buffer); typename headers_range >::type connection_range = headers(response_)["Connection"]; @@ -155,7 +155,7 @@ struct https_sync_connection void close_socket() { timer_.cancel(); std::error_code ignored; - socket_.lowest_layer().shutdown(asio::ip::tcp::socket::shutdown_both, + socket_.lowest_layer().shutdown(::asio::ip::tcp::socket::shutdown_both, ignored); if (ignored) { return; @@ -173,11 +173,11 @@ struct https_sync_connection } int timeout_; - asio::deadline_timer timer_; + ::asio::deadline_timer timer_; resolver_type& resolver_; resolver_function_type resolve_; - asio::ssl::context context_; - asio::ssl::stream socket_; + ::asio::ssl::context context_; + ::asio::ssl::stream<::asio::ip::tcp::socket> socket_; }; } // namespace impl diff --git a/boost/network/protocol/http/client/options.hpp b/boost/network/protocol/http/client/options.hpp index 2c109a88d..d91e9fe5a 100644 --- a/boost/network/protocol/http/client/options.hpp +++ b/boost/network/protocol/http/client/options.hpp @@ -133,8 +133,8 @@ class client_options { return *this; } - /// Provide an `asio::io_service` hosted in a shared pointer. - client_options& io_service(std::shared_ptr v) { + /// Provide an `::asio::io_service` hosted in a shared pointer. + client_options& io_service(std::shared_ptr<::asio::io_service> v) { io_service_ = v; return *this; } @@ -184,7 +184,7 @@ class client_options { long openssl_options() const { return openssl_options_; } - std::shared_ptr io_service() const { return io_service_; } + std::shared_ptr<::asio::io_service> io_service() const { return io_service_; } bool always_verify_peer() const { return always_verify_peer_; } @@ -200,7 +200,7 @@ class client_options { boost::optional openssl_ciphers_; boost::optional openssl_sni_hostname_; long openssl_options_; - std::shared_ptr io_service_; + std::shared_ptr<::asio::io_service> io_service_; bool always_verify_peer_; int timeout_; }; diff --git a/boost/network/protocol/http/client/pimpl.hpp b/boost/network/protocol/http/client/pimpl.hpp index 2f7f28c67..33dc5ae92 100644 --- a/boost/network/protocol/http/client/pimpl.hpp +++ b/boost/network/protocol/http/client/pimpl.hpp @@ -74,7 +74,7 @@ struct basic_client_impl optional const& private_key_file, optional const& ciphers, optional const& sni_hostname, long ssl_options, - std::shared_ptr service, int timeout) + std::shared_ptr<::asio::io_service> service, int timeout) : base_type(cache_resolved, follow_redirect, always_verify_peer, timeout, service, certificate_filename, verify_path, certificate_file, private_key_file, ciphers, sni_hostname, ssl_options) {} diff --git a/boost/network/protocol/http/client/sync_impl.hpp b/boost/network/protocol/http/client/sync_impl.hpp index 4f07446f5..f902b73a9 100644 --- a/boost/network/protocol/http/client/sync_impl.hpp +++ b/boost/network/protocol/http/client/sync_impl.hpp @@ -37,8 +37,8 @@ struct sync_client typedef std::function body_generator_function_type; friend struct basic_client_impl; - std::shared_ptr service_ptr; - asio::io_service& service_; + std::shared_ptr<::asio::io_service> service_ptr; + ::asio::io_service& service_; resolver_type resolver_; optional certificate_filename_; optional verify_path_; @@ -51,7 +51,7 @@ struct sync_client sync_client( bool cache_resolved, bool follow_redirect, bool always_verify_peer, - int timeout, std::shared_ptr service, + int timeout, std::shared_ptr<::asio::io_service> service, optional certificate_filename = optional(), optional verify_path = optional(), optional certificate_file = optional(), @@ -61,7 +61,7 @@ struct sync_client long ssl_options = 0) : connection_base(cache_resolved, follow_redirect, timeout), service_ptr(service.get() ? service - : std::make_shared()), + : std::make_shared<::asio::io_service>()), service_(*service_ptr), resolver_(service_), certificate_filename_(std::move(certificate_filename)), diff --git a/boost/network/protocol/http/impl/response.ipp b/boost/network/protocol/http/impl/response.ipp index 24055776c..18039e6a7 100644 --- a/boost/network/protocol/http/impl/response.ipp +++ b/boost/network/protocol/http/impl/response.ipp @@ -100,9 +100,9 @@ struct basic_response { /// underlying memory blocks, therefore the reply object must remain /// valid and /// not be changed until the write operation has completed. - std::vector to_buffers() { - using asio::const_buffer; - using asio::buffer; + std::vector<::asio::const_buffer> to_buffers() { + using ::asio::const_buffer; + using ::asio::buffer; static const char name_value_separator[] = {':', ' '}; static const char crlf[] = {'\r', '\n'}; std::vector buffers; @@ -408,13 +408,13 @@ struct basic_response { } } - asio::const_buffer trim_null(asio::const_buffer buffer) { - std::size_t size = asio::buffer_size(buffer); - return asio::buffer(buffer, size - 1); + ::asio::const_buffer trim_null(::asio::const_buffer buffer) { + std::size_t size = ::asio::buffer_size(buffer); + return ::asio::buffer(buffer, size - 1); } - asio::const_buffer to_buffer(status_type status) { - using asio::buffer; + ::asio::const_buffer to_buffer(status_type status) { + using ::asio::buffer; switch (status) { // 2xx Success case basic_response::ok: diff --git a/boost/network/protocol/http/policies/async_resolver.hpp b/boost/network/protocol/http/policies/async_resolver.hpp index ac30d1586..ebbba6679 100644 --- a/boost/network/protocol/http/policies/async_resolver.hpp +++ b/boost/network/protocol/http/policies/async_resolver.hpp @@ -39,8 +39,8 @@ struct async_resolver : std::enable_shared_from_this > { protected: bool cache_resolved_; endpoint_cache endpoint_cache_; - std::shared_ptr service_; - std::shared_ptr resolver_strand_; + std::shared_ptr<::asio::io_service> service_; + std::shared_ptr<::asio::io_service::strand> resolver_strand_; explicit async_resolver(bool cache_resolved) : cache_resolved_(cache_resolved), endpoint_cache_() {} diff --git a/boost/network/protocol/http/policies/pooled_connection.hpp b/boost/network/protocol/http/policies/pooled_connection.hpp index 845dd0d4a..ab5ebca57 100644 --- a/boost/network/protocol/http/policies/pooled_connection.hpp +++ b/boost/network/protocol/http/policies/pooled_connection.hpp @@ -110,12 +110,12 @@ struct pooled_connection_policy : resolver_policy::type { response_ << ::boost::network::source(request_.host()); pimpl->send_request_impl(method, request_, generator); - asio::streambuf response_buffer; + ::asio::streambuf response_buffer; try { pimpl->read_status(response_, response_buffer); } catch (std::system_error& e) { - if (!retry && e.code() == asio::error::eof) { + if (!retry && e.code() == ::asio::error::eof) { retry = true; pimpl->init_socket(request_.host(), std::to_string(request_.port())); diff --git a/boost/network/protocol/http/policies/simple_connection.hpp b/boost/network/protocol/http/policies/simple_connection.hpp index 5a96c5ade..118b41096 100644 --- a/boost/network/protocol/http/policies/simple_connection.hpp +++ b/boost/network/protocol/http/policies/simple_connection.hpp @@ -80,7 +80,7 @@ struct simple_connection_policy : resolver_policy::type { response_ = basic_response(); response_ << network::source(request_.host()); - asio::streambuf response_buffer; + ::asio::streambuf response_buffer; pimpl->read_status(response_, response_buffer); pimpl->read_headers(response_, response_buffer); if (get_body) pimpl->read_body(response_, response_buffer); diff --git a/boost/network/protocol/http/server/async_connection.hpp b/boost/network/protocol/http/server/async_connection.hpp index e5c361ab6..f7b0b328d 100644 --- a/boost/network/protocol/http/server/async_connection.hpp +++ b/boost/network/protocol/http/server/async_connection.hpp @@ -183,7 +183,7 @@ struct async_connection public: async_connection( - asio::io_service& io_service, Handler& handler, + ::asio::io_service& io_service, Handler& handler, utils::thread_pool& thread_pool, std::shared_ptr ctx = std::shared_ptr()) : strand(io_service), @@ -206,7 +206,7 @@ struct async_connection ~async_connection() throw() { std::error_code ignored; - socket_.shutdown(asio::ip::tcp::socket::shutdown_receive, ignored); + socket_.shutdown(::asio::ip::tcp::socket::shutdown_receive, ignored); } /** @@ -321,7 +321,7 @@ struct async_connection */ template typename disable_if< - is_base_of, void>::type + is_base_of<::asio::const_buffer, typename Range::value_type>, void>::type write(Range const& range, Callback const& callback) { lock_guard lock(headers_mutex); if (error_encountered) @@ -330,15 +330,15 @@ struct async_connection } /** - * Writes a given set of `asio::const_buffer`s out using a more efficient + * Writes a given set of `::asio::const_buffer`s out using a more efficient * implementation. * - * @param[in] seq A sequence of `asio::const_buffer` objects. + * @param[in] seq A sequence of `::asio::const_buffer` objects. * @param[in] callback A function of type `void(std::error_code)`. */ template typename enable_if< - is_base_of, + is_base_of<::asio::const_buffer, typename ConstBufferSeq::value_type>, void>::type write(ConstBufferSeq const& seq, Callback const& callback) { write_vec_impl(seq, callback, shared_array_list(), shared_buffers()); @@ -389,7 +389,7 @@ struct async_connection } auto self = this->shared_from_this(); - socket().async_read_some(asio::buffer(read_buffer_), + socket().async_read_some(::asio::buffer(read_buffer_), strand.wrap([this, self, callback]( std::error_code ec, size_t bytes_transferred) { callback(ec, bytes_transferred); @@ -432,15 +432,15 @@ struct async_connection array; typedef std::list > array_list; typedef std::shared_ptr shared_array_list; - typedef std::shared_ptr > shared_buffers; + typedef std::shared_ptr > shared_buffers; typedef request_parser request_parser_type; typedef std::lock_guard lock_guard; typedef std::list > pending_actions_list; - asio::io_service::strand strand; + ::asio::io_service::strand strand; Handler& handler; utils::thread_pool& thread_pool_; - asio::streambuf headers_buffer; + ::asio::streambuf headers_buffer; boost::network::stream_handler socket_; bool handshake_done; volatile bool headers_already_sent, headers_in_progress; @@ -472,14 +472,14 @@ struct async_connection auto self = this->shared_from_this(); #ifdef BOOST_NETWORK_ENABLE_HTTPS if (socket_.is_ssl_enabled() && !handshake_done) { - socket_.async_handshake(asio::ssl::stream_base::server, + socket_.async_handshake(::asio::ssl::stream_base::server, [this, self, state](std::error_code ec) { handle_handshake(ec, state); }); } else { #endif socket_.async_read_some( - asio::buffer(read_buffer_), + ::asio::buffer(read_buffer_), strand.wrap([this, self, state](std::error_code ec, size_t bytes_transferred) { handle_read_data(state, ec, bytes_transferred); @@ -604,8 +604,8 @@ struct async_connection "text/plain\r\nContent-Length: 12\r\n\r\nBad Request."; auto self = this->shared_from_this(); - asio::async_write( - socket(), asio::buffer(bad_request, strlen(bad_request)), + ::asio::async_write( + socket(), ::asio::buffer(bad_request, strlen(bad_request)), strand.wrap([this, self](std::error_code ec, size_t bytes_transferred) { client_error_sent(ec, bytes_transferred); })); @@ -614,7 +614,7 @@ struct async_connection void client_error_sent(std::error_code const& ec, std::size_t) { if (!ec) { std::error_code ignored; - socket().shutdown(asio::ip::tcp::socket::shutdown_both, ignored); + socket().shutdown(::asio::ip::tcp::socket::shutdown_both, ignored); socket().close(ignored); } else { error_encountered = in_place(ec); @@ -625,7 +625,7 @@ struct async_connection if (headers_in_progress) return; headers_in_progress = true; auto self = this->shared_from_this(); - asio::async_write(socket(), headers_buffer, + ::asio::async_write(socket(), headers_buffer, strand.wrap([this, self, callback]( std::error_code ec, size_t bytes_transferred) { handle_write_headers(callback, ec, bytes_transferred); @@ -675,7 +675,7 @@ struct async_connection BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE; shared_array_list temporaries = std::make_shared(); shared_buffers buffers = - std::make_shared >(0); + std::make_shared >(0); std::size_t range_size = boost::distance(range); buffers->reserve((range_size / connection_buffer_size) + @@ -687,7 +687,7 @@ struct async_connection std::shared_ptr new_array = std::make_shared(); boost::copy(range | sliced(0, slice_size), new_array->begin()); temporaries->push_back(new_array); - buffers->push_back(asio::buffer(new_array->data(), slice_size)); + buffers->push_back(::asio::buffer(new_array->data(), slice_size)); std::advance(start, slice_size); range = boost::make_iterator_range(start, end); range_size = boost::distance(range); @@ -717,7 +717,7 @@ struct async_connection pending_actions.push_back(continuation); return; } - asio::async_write( + ::asio::async_write( socket_, seq, [this, self, callback, temporaries, buffers]( std::error_code ec, size_t bytes_transferred) { handle_write(callback, temporaries, buffers, ec, bytes_transferred); diff --git a/boost/network/protocol/http/server/async_server.hpp b/boost/network/protocol/http/server/async_server.hpp index 954e0a5c3..8c12aee74 100644 --- a/boost/network/protocol/http/server/async_server.hpp +++ b/boost/network/protocol/http/server/async_server.hpp @@ -114,7 +114,7 @@ struct async_server_base : server_storage_base, socket_options_base { Handler &handler; string_type address_, port_; std::shared_ptr thread_pool; - asio::ip::tcp::acceptor acceptor; + ::asio::ip::tcp::acceptor acceptor; bool stopping; connection_ptr new_connection; std::mutex listening_mutex_; @@ -160,7 +160,7 @@ struct async_server_base : server_storage_base, socket_options_base { } void start_listening() { - using asio::ip::tcp; + using ::asio::ip::tcp; std::error_code error; // this allows repeated cycles of run -> stop -> run service_.reset(); @@ -185,7 +185,7 @@ struct async_server_base : server_storage_base, socket_options_base { << port_); return; } - acceptor.listen(asio::socket_base::max_connections, error); + acceptor.listen(::asio::socket_base::max_connections, error); if (error) { BOOST_NETWORK_MESSAGE("Error listening on socket: '" << error << "' on " << address_ << ":" << port_); diff --git a/boost/network/protocol/http/server/options.hpp b/boost/network/protocol/http/server/options.hpp index d3d9f03a1..fd90cc0a7 100644 --- a/boost/network/protocol/http/server/options.hpp +++ b/boost/network/protocol/http/server/options.hpp @@ -71,7 +71,7 @@ struct server_options { } /// Provides an Asio io_service for the server. Default is nullptr. - server_options &io_service(std::shared_ptr v) { + server_options &io_service(std::shared_ptr<::asio::io_service> v) { io_service_ = v; return *this; } @@ -120,26 +120,26 @@ struct server_options { /// Set the socket receive buffer size. Unset by default. server_options &receive_buffer_size( - asio::socket_base::receive_buffer_size v) { + ::asio::socket_base::receive_buffer_size v) { receive_buffer_size_ = v; return *this; } /// Set the send buffer size. Unset by default. - server_options &send_buffer_size(asio::socket_base::send_buffer_size v) { + server_options &send_buffer_size(::asio::socket_base::send_buffer_size v) { send_buffer_size_ = v; return *this; } /// Set the socket receive low watermark. Unset by default. server_options &receive_low_watermark( - asio::socket_base::receive_low_watermark v) { + ::asio::socket_base::receive_low_watermark v) { receive_low_watermark_ = v; return *this; } /// Set the socket send low watermark. Unset by default. - server_options &send_low_watermark(asio::socket_base::send_low_watermark v) { + server_options &send_low_watermark(::asio::socket_base::send_low_watermark v) { send_low_watermark_ = v; return *this; } @@ -151,7 +151,7 @@ struct server_options { } /// Returns the provided Asio io_service. - std::shared_ptr io_service() const { return io_service_; } + std::shared_ptr<::asio::io_service> io_service() const { return io_service_; } /// Returns the address to listen on. string_type address() const { return address_; } @@ -178,25 +178,25 @@ struct server_options { size_t linger_timeout() const { return linger_timeout_; } /// Returns the optional receive buffer size. - boost::optional receive_buffer_size() + boost::optional<::asio::socket_base::receive_buffer_size> receive_buffer_size() const { return receive_buffer_size_; } /// Returns the optional send buffer size. - boost::optional send_buffer_size() + boost::optional<::asio::socket_base::send_buffer_size> send_buffer_size() const { return send_buffer_size_; } /// Returns the optional receive low watermark. - boost::optional + boost::optional<::asio::socket_base::receive_low_watermark> receive_low_watermark() const { return receive_low_watermark_; } /// Returns the optional send low watermark. - boost::optional send_low_watermark() + boost::optional<::asio::socket_base::send_low_watermark> send_low_watermark() const { return send_low_watermark_; } @@ -229,7 +229,7 @@ struct server_options { } private: - std::shared_ptr io_service_; + std::shared_ptr<::asio::io_service> io_service_; Handler &handler_; string_type address_; string_type port_; @@ -238,11 +238,11 @@ struct server_options { bool non_blocking_io_; bool linger_; size_t linger_timeout_; - boost::optional receive_buffer_size_; - boost::optional send_buffer_size_; - boost::optional + boost::optional<::asio::socket_base::receive_buffer_size> receive_buffer_size_; + boost::optional<::asio::socket_base::send_buffer_size> send_buffer_size_; + boost::optional<::asio::socket_base::receive_low_watermark> receive_low_watermark_; - boost::optional send_low_watermark_; + boost::optional<::asio::socket_base::send_low_watermark> send_low_watermark_; std::shared_ptr thread_pool_; std::shared_ptr context_; }; diff --git a/boost/network/protocol/http/server/socket_options_base.hpp b/boost/network/protocol/http/server/socket_options_base.hpp index dc1bd15c5..4e5aa6390 100644 --- a/boost/network/protocol/http/server/socket_options_base.hpp +++ b/boost/network/protocol/http/server/socket_options_base.hpp @@ -14,15 +14,15 @@ namespace http { struct socket_options_base { protected: - asio::socket_base::reuse_address acceptor_reuse_address; - asio::socket_base::enable_connection_aborted acceptor_report_aborted; - boost::optional receive_buffer_size; - boost::optional send_buffer_size; - boost::optional + ::asio::socket_base::reuse_address acceptor_reuse_address; + ::asio::socket_base::enable_connection_aborted acceptor_report_aborted; + boost::optional<::asio::socket_base::receive_buffer_size> receive_buffer_size; + boost::optional<::asio::socket_base::send_buffer_size> send_buffer_size; + boost::optional<::asio::socket_base::receive_low_watermark> receive_low_watermark; - boost::optional send_low_watermark; + boost::optional<::asio::socket_base::send_low_watermark> send_low_watermark; bool non_blocking_io; - asio::socket_base::linger linger; + ::asio::socket_base::linger linger; template explicit socket_options_base(server_options const &options) @@ -35,12 +35,12 @@ struct socket_options_base { non_blocking_io(options.non_blocking_io()), linger(options.linger(), options.linger_timeout()) {} - void acceptor_options(asio::ip::tcp::acceptor &acceptor) { + void acceptor_options(::asio::ip::tcp::acceptor &acceptor) { acceptor.set_option(acceptor_reuse_address); acceptor.set_option(acceptor_report_aborted); } - void socket_options(asio::ip::tcp::socket &socket) { + void socket_options(::asio::ip::tcp::socket &socket) { std::error_code ignored; socket.non_blocking(non_blocking_io); socket.set_option(linger, ignored); diff --git a/boost/network/protocol/http/server/storage_base.hpp b/boost/network/protocol/http/server/storage_base.hpp index 9383e5e92..9e83ce2e6 100644 --- a/boost/network/protocol/http/server/storage_base.hpp +++ b/boost/network/protocol/http/server/storage_base.hpp @@ -22,11 +22,11 @@ struct server_storage_base { explicit server_storage_base(server_options const& options) : self_service_(options.io_service() ? options.io_service() - : std::make_shared()), + : std::make_shared<::asio::io_service>()), service_(*self_service_) {} - std::shared_ptr self_service_; - asio::io_service& service_; + std::shared_ptr<::asio::io_service> self_service_; + ::asio::io_service& service_; }; } /* http */ diff --git a/boost/network/protocol/http/traits/resolver.hpp b/boost/network/protocol/http/traits/resolver.hpp index cfcfc19fd..350fa2396 100644 --- a/boost/network/protocol/http/traits/resolver.hpp +++ b/boost/network/protocol/http/traits/resolver.hpp @@ -26,9 +26,9 @@ struct unsupported_tag; template struct resolver : mpl::if_, is_http >, - asio::ip::tcp::resolver, + ::asio::ip::tcp::resolver, typename mpl::if_, is_http >, - asio::ip::udp::resolver, + ::asio::ip::udp::resolver, unsupported_tag >::type> { static_assert(mpl::not_, is_tcp > >::value, "Transport protocol must be TCP or UDP"); diff --git a/boost/network/protocol/stream_handler.hpp b/boost/network/protocol/stream_handler.hpp index ae355b724..16fafc665 100644 --- a/boost/network/protocol/stream_handler.hpp +++ b/boost/network/protocol/stream_handler.hpp @@ -28,15 +28,15 @@ namespace boost { namespace network { -typedef asio::ip::tcp::socket tcp_socket; +typedef ::asio::ip::tcp::socket tcp_socket; #ifndef BOOST_NETWORK_ENABLE_HTTPS typedef tcp_socket stream_handler; typedef void ssl_context; #else -typedef asio::ssl::stream ssl_socket; -typedef asio::ssl::context ssl_context; +typedef ::asio::ssl::stream<::asio::ip::tcp::socket> ssl_socket; +typedef ::asio::ssl::context ssl_context; struct stream_handler { public: @@ -48,7 +48,7 @@ struct stream_handler { stream_handler(std::shared_ptr socket) : ssl_sock_(std::move(socket)), ssl_enabled(true) {} - stream_handler(asio::io_service& io, + stream_handler(::asio::io_service& io, std::shared_ptr ctx = std::shared_ptr()) { tcp_sock_ = std::make_shared(boost::ref(io)); @@ -117,13 +117,13 @@ struct stream_handler { } } - void shutdown(asio::socket_base::shutdown_type st, + void shutdown(::asio::socket_base::shutdown_type st, std::error_code& e) { try { if (ssl_enabled) { ssl_sock_->shutdown(e); } else { - tcp_sock_->shutdown(asio::ip::tcp::socket::shutdown_send, e); + tcp_sock_->shutdown(::asio::ip::tcp::socket::shutdown_send, e); } } catch (const std::error_code& e) { diff --git a/boost/network/uri/builder.hpp b/boost/network/uri/builder.hpp index c30d1fd86..759ffc65a 100644 --- a/boost/network/uri/builder.hpp +++ b/boost/network/uri/builder.hpp @@ -51,23 +51,23 @@ class builder { builder &host(const string_type &host) { return set_host(host); } - builder &set_host(const asio::ip::address &address) { + builder &set_host(const ::asio::ip::address &address) { uri_.uri_.append(address.to_string()); uri_.parse(); return *this; } - builder &host(const asio::ip::address &host) { return set_host(host); } + builder &host(const ::asio::ip::address &host) { return set_host(host); } - builder &set_host(const asio::ip::address_v4 &address) { + builder &set_host(const ::asio::ip::address_v4 &address) { uri_.uri_.append(address.to_string()); uri_.parse(); return *this; } - builder &host(const asio::ip::address_v4 &host) { return set_host(host); } + builder &host(const ::asio::ip::address_v4 &host) { return set_host(host); } - builder &set_host(const asio::ip::address_v6 &address) { + builder &set_host(const ::asio::ip::address_v6 &address) { uri_.uri_.append("["); uri_.uri_.append(address.to_string()); uri_.uri_.append("]"); @@ -75,7 +75,7 @@ class builder { return *this; } - builder &host(const asio::ip::address_v6 &host) { return set_host(host); } + builder &host(const ::asio::ip::address_v6 &host) { return set_host(host); } builder &set_port(const string_type &port) { uri_.uri_.append(":"); diff --git a/boost/network/utils/thread_pool.hpp b/boost/network/utils/thread_pool.hpp index 361bbc1c4..6a66b7392 100644 --- a/boost/network/utils/thread_pool.hpp +++ b/boost/network/utils/thread_pool.hpp @@ -17,9 +17,9 @@ namespace boost { namespace network { namespace utils { -typedef std::shared_ptr io_service_ptr; +typedef std::shared_ptr<::asio::io_service> io_service_ptr; typedef std::shared_ptr worker_threads_ptr; -typedef std::shared_ptr sentinel_ptr; +typedef std::shared_ptr<::asio::io_service::work> sentinel_ptr; class thread_pool { public: @@ -52,7 +52,7 @@ class thread_pool { BOOST_SCOPE_EXIT_END if (!io_service_.get()) { - io_service_.reset(new asio::io_service); + io_service_.reset(new ::asio::io_service); } if (!worker_threads_.get()) { @@ -60,7 +60,7 @@ class thread_pool { } if (!sentinel_.get()) { - sentinel_.reset(new asio::io_service::work(*io_service_)); + sentinel_.reset(new ::asio::io_service::work(*io_service_)); } for (std::size_t counter = 0; counter < threads_; ++counter) { From a1e16f385369c046c59a3907b80d278c951308ff Mon Sep 17 00:00:00 2001 From: Grzegorz Baran Date: Wed, 20 Apr 2016 19:29:26 +0200 Subject: [PATCH 013/102] Fix for: Body callback function is not called when some errors occur (timeout etc.) #640 --- .../http/client/connection/async_normal.hpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/boost/network/protocol/http/client/connection/async_normal.hpp b/boost/network/protocol/http/client/connection/async_normal.hpp index 35c12b365..240a42a43 100644 --- a/boost/network/protocol/http/client/connection/async_normal.hpp +++ b/boost/network/protocol/http/client/connection/async_normal.hpp @@ -118,7 +118,7 @@ struct http_async_connection } private: - void set_errors(std::error_code const& ec) { + void set_errors(std::error_code const& ec, body_callback_function_type callback) { std::system_error error(ec); this->version_promise.set_exception(std::make_exception_ptr(error)); this->status_promise.set_exception(std::make_exception_ptr(error)); @@ -127,6 +127,8 @@ struct http_async_connection this->source_promise.set_exception(std::make_exception_ptr(error)); this->destination_promise.set_exception(std::make_exception_ptr(error)); this->body_promise.set_exception(std::make_exception_ptr(error)); + if ( callback ) + callback( boost::iterator_range(), ec ); this->timer_.cancel(); } @@ -155,9 +157,7 @@ struct http_async_connection generator, std::make_pair(++iter_copy, resolver_iterator()), ec); })); } else { - set_errors(ec ? ec : ::asio::error::host_not_found); - boost::iterator_range range; - if (callback) callback(range, ec); + set_errors((ec ? ec : ::asio::error::host_not_found), callback); } } @@ -168,7 +168,7 @@ struct http_async_connection resolver_iterator_pair endpoint_range, std::error_code const& ec) { if (is_timedout_) { - set_errors(::asio::error::timed_out); + set_errors(::asio::error::timed_out, callback); } else if (!ec) { BOOST_ASSERT(delegate_.get() != 0); auto self = this->shared_from_this(); @@ -193,9 +193,7 @@ struct http_async_connection ec); })); } else { - set_errors(ec ? ec : ::asio::error::host_not_found); - boost::iterator_range range; - if (callback) callback(range, ec); + set_errors((ec ? ec : ::asio::error::host_not_found), callback); } } } @@ -239,7 +237,7 @@ struct http_async_connection ec, bytes_transferred); })); } else { - set_errors(is_timedout_ ? ::asio::error::timed_out : ec); + set_errors((is_timedout_ ? ::asio::error::timed_out : ec), callback); } } @@ -322,6 +320,8 @@ struct http_async_connection // We short-circuit here because the user does not want to get the // body (in the case of a HEAD request). this->body_promise.set_value(""); + if ( callback ) + callback( boost::iterator_range(), ::asio::error::eof ); this->destination_promise.set_value(""); this->source_promise.set_value(""); // this->part.assign('\0'); @@ -446,8 +446,8 @@ struct http_async_connection BOOST_ASSERT(false && "Bug, report this to the developers!"); } } else { - std::system_error error(is_timedout_ ? ::asio::error::timed_out - : ec); + std::error_code report_code = is_timedout_ ? ::asio::error::timed_out : ec; + std::system_error error(report_code); this->source_promise.set_exception(std::make_exception_ptr(error)); this->destination_promise.set_exception(std::make_exception_ptr(error)); switch (state) { @@ -467,6 +467,8 @@ struct http_async_connection // so no exception should be set this->body_promise.set_exception(std::make_exception_ptr(error)); } + else + callback( boost::iterator_range(), report_code ); break; default: BOOST_ASSERT(false && "Bug, report this to the developers!"); From 68507ace79ab43bd50b74a33220a3f0186f259b9 Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Wed, 20 Apr 2016 03:03:06 +1000 Subject: [PATCH 014/102] Fixes #635 - bug in async server's connection read This changes the example file server to use the read handler for POST/PUT requests. This currently assumes that there's a content-length header (not much error handling is happening here, but it's meant as a proof of concept anyway). Using this code path in an example should be good enough for the moment until we have better tests and a better API for this functionality. --- .../protocol/http/server/async_connection.hpp | 13 +-- libs/network/example/http/fileserver.cpp | 79 ++++++++++++++++--- 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/boost/network/protocol/http/server/async_connection.hpp b/boost/network/protocol/http/server/async_connection.hpp index e5c361ab6..4a6dbdf63 100644 --- a/boost/network/protocol/http/server/async_connection.hpp +++ b/boost/network/protocol/http/server/async_connection.hpp @@ -378,7 +378,7 @@ struct async_connection boost::throw_exception(std::system_error(*error_encountered)); if (new_start != read_buffer_.begin()) { input_range input = - boost::make_iterator_range(new_start, read_buffer_.end()); + boost::make_iterator_range(new_start, data_end); buffer_type::iterator start_tmp = new_start; new_start = read_buffer_.begin(); auto self = this->shared_from_this(); @@ -389,11 +389,12 @@ struct async_connection } auto self = this->shared_from_this(); - socket().async_read_some(asio::buffer(read_buffer_), - strand.wrap([this, self, callback]( - std::error_code ec, size_t bytes_transferred) { - callback(ec, bytes_transferred); - })); + socket().async_read_some( + asio::buffer(read_buffer_), + strand.wrap([this, self, callback](std::error_code ec, + size_t bytes_transferred) { + this->wrap_read_handler(callback, ec, bytes_transferred); + })); } /// Returns a reference to the underlying socket. diff --git a/libs/network/example/http/fileserver.cpp b/libs/network/example/http/fileserver.cpp index 40ccf7ccf..7f3346941 100644 --- a/libs/network/example/http/fileserver.cpp +++ b/libs/network/example/http/fileserver.cpp @@ -21,7 +21,6 @@ struct file_server; typedef http::server server; struct file_cache { - typedef std::map > region_map; typedef std::map > meta_map; @@ -66,7 +65,8 @@ struct file_cache { regions.insert(std::make_pair(real_filename, std::make_pair(region, size))); static server::response_header common_headers[] = { - {"Connection", "close"}, {"Content-Type", "x-application/octet-stream"}, + {"Connection", "close"}, + {"Content-Type", "x-application/octet-stream"}, {"Content-Length", "0"}}; std::vector headers(common_headers, common_headers + 3); @@ -91,8 +91,7 @@ struct file_cache { static std::vector empty_vector; auto headers = file_headers.find(doc_root_ + path); if (headers != file_headers.end()) { - auto begin = headers->second.begin(), - end = headers->second.end(); + auto begin = headers->second.begin(), end = headers->second.end(); return boost::make_iterator_range(begin, end); } else return boost::make_iterator_range(empty_vector); @@ -138,7 +137,7 @@ struct connection_handler : std::enable_shared_from_this { asio::const_buffers_1( static_cast(mmaped_region.first) + offset, rightmost_bound - offset), - [=] (std::error_code const &ec) { + [=](std::error_code const &ec) { self->handle_chunk(mmaped_region, rightmost_bound, connection, ec); }); } @@ -146,7 +145,7 @@ struct connection_handler : std::enable_shared_from_this { void handle_chunk(std::pair mmaped_region, off_t offset, server::connection_ptr connection, std::error_code const &ec) { - assert(offset>=0); + assert(offset >= 0); if (!ec && static_cast(offset) < mmaped_region.second) send_file(mmaped_region, offset, connection); } @@ -154,6 +153,59 @@ struct connection_handler : std::enable_shared_from_this { file_cache &file_cache_; }; +struct input_consumer : public std::enable_shared_from_this { + // Maximum size for incoming request bodies. + static constexpr std::size_t MAX_INPUT_BODY_SIZE = 2 << 16; + + explicit input_consumer(std::shared_ptr h, + server::request r) + : request_(std::move(r)), handler_(std::move(h)), content_length_{0} { + for (const auto &header : request_.headers) { + if (boost::iequals(header.name, "content-length")) { + content_length_ = std::stoul(header.value); + std::cerr << "Content length: " << content_length_ << '\n'; + break; + } + } + } + + void operator()(server::connection::input_range input, std::error_code ec, + std::size_t bytes_transferred, + server::connection_ptr connection) { + std::cerr << "Callback: " << bytes_transferred << "; ec = " << ec << '\n'; + if (ec == asio::error::eof) return; + if (!ec) { + if (empty(input)) + return (*handler_)(request_.destination, connection, true); + request_.body.insert(request_.body.end(), boost::begin(input), + boost::end(input)); + if (request_.body.size() > MAX_INPUT_BODY_SIZE) { + connection->set_status(server::connection::bad_request); + static server::response_header error_headers[] = { + {"Connection", "close"}}; + connection->set_headers( + boost::make_iterator_range(error_headers, error_headers + 1)); + connection->write("Body too large."); + return; + } + std::cerr << "Body: " << request_.body << '\n'; + if (request_.body.size() == content_length_) + return (*handler_)(request_.destination, connection, true); + std::cerr << "Scheduling another read...\n"; + auto self = this->shared_from_this(); + connection->read([self](server::connection::input_range input, + std::error_code ec, std::size_t bytes_transferred, + server::connection_ptr connection) { + (*self)(input, ec, bytes_transferred, connection); + }); + } + } + + server::request request_; + std::shared_ptr handler_; + size_t content_length_; +}; + struct file_server { explicit file_server(file_cache &cache) : cache_(cache) {} @@ -165,6 +217,14 @@ struct file_server { } else if (request.method == "GET") { std::shared_ptr h(new connection_handler(cache_)); (*h)(request.destination, connection, true); + } else if (request.method == "PUT" || request.method == "POST") { + auto h = std::make_shared(cache_); + auto c = std::make_shared(h, request); + connection->read([c](server::connection::input_range input, + std::error_code ec, std::size_t bytes_transferred, + server::connection_ptr connection) { + (*c)(input, ec, bytes_transferred, connection); + }); } else { static server::response_header error_headers[] = { {"Connection", "close"}}; @@ -184,11 +244,10 @@ int main(int, char *[]) { file_server handler(cache); server::options options(handler); server instance(options.thread_pool(std::make_shared(4)) - .address("0.0.0.0") - .port("8000")); + .address("0.0.0.0") + .port("8000")); instance.run(); - } - catch (std::exception &e) { + } catch (std::exception &e) { std::cerr << e.what() << std::endl; } } From cf080ef006cc1081bc007a2c332be01327a900d3 Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Wed, 20 Apr 2016 03:03:06 +1000 Subject: [PATCH 015/102] Fixes #635 - bug in async server's connection read This changes the example file server to use the read handler for POST/PUT requests. This currently assumes that there's a content-length header (not much error handling is happening here, but it's meant as a proof of concept anyway). Using this code path in an example should be good enough for the moment until we have better tests and a better API for this functionality. --- .../protocol/http/server/async_connection.hpp | 5 +- libs/network/example/http/fileserver.cpp | 79 ++++++++++++++++--- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/boost/network/protocol/http/server/async_connection.hpp b/boost/network/protocol/http/server/async_connection.hpp index f7b0b328d..007f6bb7c 100644 --- a/boost/network/protocol/http/server/async_connection.hpp +++ b/boost/network/protocol/http/server/async_connection.hpp @@ -378,7 +378,7 @@ struct async_connection boost::throw_exception(std::system_error(*error_encountered)); if (new_start != read_buffer_.begin()) { input_range input = - boost::make_iterator_range(new_start, read_buffer_.end()); + boost::make_iterator_range(new_start, data_end); buffer_type::iterator start_tmp = new_start; new_start = read_buffer_.begin(); auto self = this->shared_from_this(); @@ -392,7 +392,8 @@ struct async_connection socket().async_read_some(::asio::buffer(read_buffer_), strand.wrap([this, self, callback]( std::error_code ec, size_t bytes_transferred) { - callback(ec, bytes_transferred); + this->wrap_read_handler(callback, ec, + bytes_transferred); })); } diff --git a/libs/network/example/http/fileserver.cpp b/libs/network/example/http/fileserver.cpp index 6c02098cf..8f74ae9a1 100644 --- a/libs/network/example/http/fileserver.cpp +++ b/libs/network/example/http/fileserver.cpp @@ -21,7 +21,6 @@ struct file_server; typedef http::server server; struct file_cache { - typedef std::map > region_map; typedef std::map > meta_map; @@ -66,7 +65,8 @@ struct file_cache { regions.insert(std::make_pair(real_filename, std::make_pair(region, size))); static server::response_header common_headers[] = { - {"Connection", "close"}, {"Content-Type", "x-application/octet-stream"}, + {"Connection", "close"}, + {"Content-Type", "x-application/octet-stream"}, {"Content-Length", "0"}}; std::vector headers(common_headers, common_headers + 3); @@ -91,8 +91,7 @@ struct file_cache { static std::vector empty_vector; auto headers = file_headers.find(doc_root_ + path); if (headers != file_headers.end()) { - auto begin = headers->second.begin(), - end = headers->second.end(); + auto begin = headers->second.begin(), end = headers->second.end(); return boost::make_iterator_range(begin, end); } else return boost::make_iterator_range(empty_vector); @@ -138,7 +137,7 @@ struct connection_handler : std::enable_shared_from_this { asio::const_buffers_1( static_cast(mmaped_region.first) + offset, rightmost_bound - offset), - [=] (std::error_code const &ec) { + [=](std::error_code const &ec) { self->handle_chunk(mmaped_region, rightmost_bound, connection, ec); }); } @@ -146,7 +145,7 @@ struct connection_handler : std::enable_shared_from_this { void handle_chunk(std::pair mmaped_region, off_t offset, server::connection_ptr connection, std::error_code const &ec) { - assert(offset>=0); + assert(offset >= 0); if (!ec && static_cast(offset) < mmaped_region.second) send_file(mmaped_region, offset, connection); } @@ -154,6 +153,59 @@ struct connection_handler : std::enable_shared_from_this { file_cache &file_cache_; }; +struct input_consumer : public std::enable_shared_from_this { + // Maximum size for incoming request bodies. + static constexpr std::size_t MAX_INPUT_BODY_SIZE = 2 << 16; + + explicit input_consumer(std::shared_ptr h, + server::request r) + : request_(std::move(r)), handler_(std::move(h)), content_length_{0} { + for (const auto &header : request_.headers) { + if (boost::iequals(header.name, "content-length")) { + content_length_ = std::stoul(header.value); + std::cerr << "Content length: " << content_length_ << '\n'; + break; + } + } + } + + void operator()(server::connection::input_range input, std::error_code ec, + std::size_t bytes_transferred, + server::connection_ptr connection) { + std::cerr << "Callback: " << bytes_transferred << "; ec = " << ec << '\n'; + if (ec == asio::error::eof) return; + if (!ec) { + if (empty(input)) + return (*handler_)(request_.destination, connection, true); + request_.body.insert(request_.body.end(), boost::begin(input), + boost::end(input)); + if (request_.body.size() > MAX_INPUT_BODY_SIZE) { + connection->set_status(server::connection::bad_request); + static server::response_header error_headers[] = { + {"Connection", "close"}}; + connection->set_headers( + boost::make_iterator_range(error_headers, error_headers + 1)); + connection->write("Body too large."); + return; + } + std::cerr << "Body: " << request_.body << '\n'; + if (request_.body.size() == content_length_) + return (*handler_)(request_.destination, connection, true); + std::cerr << "Scheduling another read...\n"; + auto self = this->shared_from_this(); + connection->read([self](server::connection::input_range input, + std::error_code ec, std::size_t bytes_transferred, + server::connection_ptr connection) { + (*self)(input, ec, bytes_transferred, connection); + }); + } + } + + server::request request_; + std::shared_ptr handler_; + size_t content_length_; +}; + struct file_server { explicit file_server(file_cache &cache) : cache_(cache) {} @@ -165,6 +217,14 @@ struct file_server { } else if (request.method == "GET") { std::shared_ptr h(new connection_handler(cache_)); (*h)(request.destination, connection, true); + } else if (request.method == "PUT" || request.method == "POST") { + auto h = std::make_shared(cache_); + auto c = std::make_shared(h, request); + connection->read([c](server::connection::input_range input, + std::error_code ec, std::size_t bytes_transferred, + server::connection_ptr connection) { + (*c)(input, ec, bytes_transferred, connection); + }); } else { static server::response_header error_headers[] = { {"Connection", "close"}}; @@ -184,11 +244,10 @@ int main(int, char *[]) { file_server handler(cache); server::options options(handler); server instance(options.thread_pool(std::make_shared(4)) - .address("0.0.0.0") - .port("8000")); + .address("0.0.0.0") + .port("8000")); instance.run(); - } - catch (std::exception &e) { + } catch (std::exception &e) { std::cerr << e.what() << std::endl; } } From 340e242e95e00908df2426b0c568834e64533995 Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Mon, 25 Apr 2016 14:36:58 +1000 Subject: [PATCH 016/102] Fixes #643 -- declare swap to be inline --- boost/network/utils/thread_pool.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boost/network/utils/thread_pool.hpp b/boost/network/utils/thread_pool.hpp index 6a66b7392..0d1e2c0d1 100644 --- a/boost/network/utils/thread_pool.hpp +++ b/boost/network/utils/thread_pool.hpp @@ -98,7 +98,8 @@ class thread_pool { sentinel_ptr sentinel_; }; -void swap(thread_pool &a, thread_pool &b) { a.swap(b); } +inline void swap(thread_pool &a, thread_pool &b) { a.swap(b); } + } // namespace utils } // namespace network } // namespace boost From 80db8c2852de97005e4a2205a7d9e409f9186d0d Mon Sep 17 00:00:00 2001 From: RyuaNerin Date: Sun, 15 May 2016 09:45:21 +0900 Subject: [PATCH 017/102] fixed version information. --- libs/network/doc/conf.py | 6 +++--- libs/network/doc/html/contents.html | 10 +++++----- libs/network/doc/html/examples.html | 10 +++++----- libs/network/doc/html/examples/http/atom_reader.html | 10 +++++----- .../doc/html/examples/http/hello_world_client.html | 10 +++++----- .../doc/html/examples/http/hello_world_server.html | 10 +++++----- libs/network/doc/html/examples/http/http_client.html | 10 +++++----- libs/network/doc/html/examples/http/simple_wget.html | 10 +++++----- .../network/doc/html/examples/http/twitter_search.html | 10 +++++----- libs/network/doc/html/getting_started.html | 10 +++++----- libs/network/doc/html/index.html | 10 +++++----- libs/network/doc/html/reference.html | 10 +++++----- libs/network/doc/html/reference/http_client.html | 10 +++++----- libs/network/doc/html/reference/http_request.html | 10 +++++----- libs/network/doc/html/reference/http_response.html | 10 +++++----- libs/network/doc/html/reference/http_server.html | 10 +++++----- libs/network/doc/html/references.html | 10 +++++----- libs/network/doc/html/search.html | 10 +++++----- libs/network/doc/html/whats_new.html | 10 +++++----- 19 files changed, 93 insertions(+), 93 deletions(-) diff --git a/libs/network/doc/conf.py b/libs/network/doc/conf.py index 79137328e..d541be499 100644 --- a/libs/network/doc/conf.py +++ b/libs/network/doc/conf.py @@ -62,9 +62,9 @@ # built documents. # # The short X.Y version. -version = '0.11' +version = '0.12' # The full version, including alpha/beta/rc tags. -release = '0.11.2' +release = '0.12.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -111,7 +111,7 @@ # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -html_title = 'cpp-netlib v0.11.2' +html_title = 'cpp-netlib v0.12.0' # A shorter title for the navigation bar. Default is the same as html_title. # html_short_title = 'cpp-netlib' diff --git a/libs/network/doc/html/contents.html b/libs/network/doc/html/contents.html index ce952c360..0c448720b 100644 --- a/libs/network/doc/html/contents.html +++ b/libs/network/doc/html/contents.html @@ -6,7 +6,7 @@ - Contents — cpp-netlib v0.11.2 + Contents — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -40,7 +40,7 @@

Navigation

  • next
  • - + @@ -231,7 +231,7 @@

    Navigation

  • next
  • - + @@ -124,7 +124,7 @@

    Navigation

  • previous |
  • - + @@ -169,7 +169,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/examples/http/hello_world_client.html b/libs/network/doc/html/examples/http/hello_world_client.html index e9ff6a48e..c83408f56 100644 --- a/libs/network/doc/html/examples/http/hello_world_client.html +++ b/libs/network/doc/html/examples/http/hello_world_client.html @@ -6,7 +6,7 @@ - “Hello world” HTTP client — cpp-netlib v0.11.2 + “Hello world” HTTP client — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -45,7 +45,7 @@

    Navigation

  • previous |
  • - + @@ -186,7 +186,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/examples/http/hello_world_server.html b/libs/network/doc/html/examples/http/hello_world_server.html index cdea75e8f..59a516872 100644 --- a/libs/network/doc/html/examples/http/hello_world_server.html +++ b/libs/network/doc/html/examples/http/hello_world_server.html @@ -6,7 +6,7 @@ - “Hello world” HTTP server — cpp-netlib v0.11.2 + “Hello world” HTTP server — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -45,7 +45,7 @@

    Navigation

  • previous |
  • - + @@ -236,7 +236,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/examples/http/http_client.html b/libs/network/doc/html/examples/http/http_client.html index b5ef618f8..33eaead94 100644 --- a/libs/network/doc/html/examples/http/http_client.html +++ b/libs/network/doc/html/examples/http/http_client.html @@ -6,7 +6,7 @@ - HTTP client — cpp-netlib v0.11.2 + HTTP client — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -45,7 +45,7 @@

    Navigation

  • previous |
  • - + @@ -200,7 +200,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/examples/http/simple_wget.html b/libs/network/doc/html/examples/http/simple_wget.html index 709d941cd..5031909b8 100644 --- a/libs/network/doc/html/examples/http/simple_wget.html +++ b/libs/network/doc/html/examples/http/simple_wget.html @@ -6,7 +6,7 @@ - Simple wget — cpp-netlib v0.11.2 + Simple wget — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -45,7 +45,7 @@

    Navigation

  • previous |
  • - + @@ -197,7 +197,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/examples/http/twitter_search.html b/libs/network/doc/html/examples/http/twitter_search.html index 62018b073..9a5a7ff75 100644 --- a/libs/network/doc/html/examples/http/twitter_search.html +++ b/libs/network/doc/html/examples/http/twitter_search.html @@ -6,7 +6,7 @@ - Twitter search — cpp-netlib v0.11.2 + Twitter search — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -45,7 +45,7 @@

    Navigation

  • previous |
  • - + @@ -203,7 +203,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/getting_started.html b/libs/network/doc/html/getting_started.html index 3c8a000cc..ec5e72de5 100644 --- a/libs/network/doc/html/getting_started.html +++ b/libs/network/doc/html/getting_started.html @@ -6,7 +6,7 @@ - Getting Started — cpp-netlib v0.11.2 + Getting Started — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -44,7 +44,7 @@

    Navigation

  • previous |
  • - + @@ -345,7 +345,7 @@

    Navigation

  • previous |
  • - + @@ -197,7 +197,7 @@

    Navigation

  • previous |
  • - + @@ -128,7 +128,7 @@

    Navigation

  • previous |
  • - + @@ -756,7 +756,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/reference/http_request.html b/libs/network/doc/html/reference/http_request.html index 2f916959f..d1a959c39 100644 --- a/libs/network/doc/html/reference/http_request.html +++ b/libs/network/doc/html/reference/http_request.html @@ -6,7 +6,7 @@ - HTTP Request — cpp-netlib v0.11.2 + HTTP Request — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -45,7 +45,7 @@

    Navigation

  • previous |
  • - + @@ -430,7 +430,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/reference/http_response.html b/libs/network/doc/html/reference/http_response.html index 8d8338e5c..b28c02e62 100644 --- a/libs/network/doc/html/reference/http_response.html +++ b/libs/network/doc/html/reference/http_response.html @@ -6,7 +6,7 @@ - HTTP Response — cpp-netlib v0.11.2 + HTTP Response — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -45,7 +45,7 @@

    Navigation

  • previous |
  • - + @@ -463,7 +463,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/reference/http_server.html b/libs/network/doc/html/reference/http_server.html index d8329e200..1826bc201 100644 --- a/libs/network/doc/html/reference/http_server.html +++ b/libs/network/doc/html/reference/http_server.html @@ -6,7 +6,7 @@ - HTTP Server API — cpp-netlib v0.11.2 + HTTP Server API — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -45,7 +45,7 @@

    Navigation

  • previous |
  • - + @@ -931,7 +931,7 @@

    Navigation

  • previous |
  • - + diff --git a/libs/network/doc/html/references.html b/libs/network/doc/html/references.html index d372a2c6a..b4f5e6a8f 100644 --- a/libs/network/doc/html/references.html +++ b/libs/network/doc/html/references.html @@ -6,7 +6,7 @@ - References — cpp-netlib v0.11.2 + References — cpp-netlib v0.12.0 @@ -14,7 +14,7 @@ - + @@ -40,7 +40,7 @@

    Navigation

  • previous
  • - + @@ -111,7 +111,7 @@

    Navigation

  • previous
  • - +