From 567f9769a9ade8d598ebb445ea6a993ed3910e7e Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Tue, 8 May 2012 18:23:55 +1000 Subject: [PATCH] C++11 features to implement server stuff. --- boost/network/message/wrappers/headers.hpp | 8 --- .../protocol/http/algorithms/flatten.hpp | 25 --------- .../protocol/http/server/connection/sync.hpp | 55 +++++++++++++++++-- libs/network/test/http/CMakeLists.txt | 2 + 4 files changed, 53 insertions(+), 37 deletions(-) delete mode 100644 boost/network/protocol/http/algorithms/flatten.hpp diff --git a/boost/network/message/wrappers/headers.hpp b/boost/network/message/wrappers/headers.hpp index 0a9bceeca..81179d8e3 100644 --- a/boost/network/message/wrappers/headers.hpp +++ b/boost/network/message/wrappers/headers.hpp @@ -13,14 +13,6 @@ namespace boost { namespace network { struct message_base; -/** headers wrapper for messages. - * - * This exposes an interface similar to a map, indexable - * using operator[] taking a string as the index and returns - * a range of iterators (std::pair) - * whose keys are all equal to the index string. - * - */ struct headers_wrapper { typedef std::multimap container_type; explicit headers_wrapper(message_base const & message); diff --git a/boost/network/protocol/http/algorithms/flatten.hpp b/boost/network/protocol/http/algorithms/flatten.hpp deleted file mode 100644 index 60fa8c468..000000000 --- a/boost/network/protocol/http/algorithms/flatten.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_FLATTEN_HPP_20120326 -#define BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_FLATTEN_HPP_20120326 - -// Copyright 2012 Dean Michael Berris . -// Copyright 2012 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 - -namespace boost { namespace network { namespace http { - -class response; - -void flatten(response const &response_, std::vector &buffers); - -} // namespace http - -} // namespace network - -} // namespace boost - -#endif // BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_FLATTEN_HPP_20120326 diff --git a/boost/network/protocol/http/server/connection/sync.hpp b/boost/network/protocol/http/server/connection/sync.hpp index 258fcd8dc..0487bd9c2 100644 --- a/boost/network/protocol/http/server/connection/sync.hpp +++ b/boost/network/protocol/http/server/connection/sync.hpp @@ -12,7 +12,10 @@ #define BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE 4096uL #endif +#include +#include #include +#include #include #include #include @@ -26,7 +29,6 @@ #include #include #include -#include namespace boost { namespace network { namespace http { @@ -187,8 +189,13 @@ class sync_server_connection : public boost::enable_shared_from_this response_buffers; - flatten(response_, response_buffers); + flatten_response(); + std::vector response_buffers(output_buffers_.size()); + std::transform(output_buffers_.begin(), output_buffers_.end(), + response_buffers.begin(), + [](buffer_type const &buffer) { + return asio::const_buffer(buffer.data(), buffer.size()); + }); boost::asio::async_write( socket_, response_buffers, @@ -217,13 +224,15 @@ class sync_server_connection : public boost::enable_shared_from_this data) { + if (boost::empty(data)) done = true; + else std::copy(begin(data), end(data), buffer.begin()); + }, buffer.size()); + if (!done) output_buffers_.emplace_back(std::move(buffer)); + } + } + + void segmented_write(std::string data) { + while (!boost::empty(data)) { + buffer_type buffer; + auto end = std::copy_n(boost::begin(data), buffer.size(), buffer.begin()); + data.erase(0, std::distance(buffer.begin(), end)); + output_buffers_.emplace_back(std::move(buffer)); + } + } + boost::asio::io_service & service_; function handler_; boost::asio::ip::tcp::socket socket_; @@ -273,6 +319,7 @@ class sync_server_connection : public boost::enable_shared_from_this output_buffers_; std::string partial_parsed; optional error_encountered; bool read_body_; diff --git a/libs/network/test/http/CMakeLists.txt b/libs/network/test/http/CMakeLists.txt index 768ced7cd..555541558 100644 --- a/libs/network/test/http/CMakeLists.txt +++ b/libs/network/test/http/CMakeLists.txt @@ -87,8 +87,10 @@ if (Boost_FOUND) target_link_libraries(cpp-netlib-http-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + cppnetlib-constants cppnetlib-uri cppnetlib-message + cppnetlib-message-wrappers cppnetlib-http-message cppnetlib-http-servers cppnetlib-http-server-parsers