From da61b4e52cb56b5ebd4314ae34d5ecd7fd87d43a Mon Sep 17 00:00:00 2001 From: Damian Jarek Date: Sun, 9 Jun 2019 20:43:49 +0200 Subject: [PATCH] Move `char_buffer` into a separate file Signed-off-by: Damian Jarek --- CHANGELOG.md | 1 + .../boost/beast/core/detail/char_buffer.hpp | 78 +++++++++++++++++++ .../boost/beast/http/detail/basic_parser.hpp | 56 +------------ .../boost/beast/http/detail/basic_parser.ipp | 2 +- .../boost/beast/http/impl/basic_parser.ipp | 2 +- 5 files changed, 83 insertions(+), 56 deletions(-) create mode 100644 include/boost/beast/core/detail/char_buffer.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 2993124b..a9e2021b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Version 259: * Remove redundant instation of `static_string` in websocket * Remove redundant use of `asio::coroutine` in `flat_stream` * Remove unused includes from `test::stream` +* Move `char_buffer` into a separate file -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/detail/char_buffer.hpp b/include/boost/beast/core/detail/char_buffer.hpp new file mode 100644 index 00000000..b1970ebc --- /dev/null +++ b/include/boost/beast/core/detail/char_buffer.hpp @@ -0,0 +1,78 @@ +// +// Copyright (c) 2019 Damian Jarek(damian.jarek93@gmail.com) +// +// 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) +// +// Official repository: https://github.com/boostorg/beast +// + +#ifndef BOOST_BEAST_CORE_DETAIL_CHAR_BUFFER_HPP +#define BOOST_BEAST_CORE_DETAIL_CHAR_BUFFER_HPP + +#include +#include +#include +#include + +namespace boost { +namespace beast { +namespace detail { + +template +class char_buffer +{ +public: + bool try_push_back(char c) + { + if (size_ == N) + return false; + buf_[size_++] = c; + return true; + } + + bool try_append(char const* first, char const* last) + { + std::size_t const n = last - first; + if (n > N - size_) + return false; + std::memmove(&buf_[size_], first, n); + size_ += n; + return true; + } + + void clear() noexcept + { + size_ = 0; + } + + char* data() noexcept + { + return buf_; + } + + char const* data() const noexcept + { + return buf_; + } + + std::size_t size() const noexcept + { + return size_; + } + + bool empty() const noexcept + { + return size_ == 0; + } + +private: + std::size_t size_= 0; + char buf_[N]; +}; + +} // detail +} // beast +} // boost + +#endif diff --git a/include/boost/beast/http/detail/basic_parser.hpp b/include/boost/beast/http/detail/basic_parser.hpp index dfe20a9a..196d1c0a 100644 --- a/include/boost/beast/http/detail/basic_parser.hpp +++ b/include/boost/beast/http/detail/basic_parser.hpp @@ -11,6 +11,7 @@ #define BOOST_BEAST_HTTP_DETAIL_BASIC_PARSER_HPP #include +#include #include #include #include @@ -23,59 +24,6 @@ namespace beast { namespace http { namespace detail { -template -class char_buffer -{ -public: - bool try_push_back(char c) - { - if (size_ == N) - return false; - buf_[size_++] = c; - return true; - } - - bool try_append(char const* first, char const* last) - { - std::size_t const n = last - first; - if (n > N - size_) - return false; - std::memmove(&buf_[size_], first, n); - size_ += n; - return true; - } - - void clear() noexcept - { - size_ = 0; - } - - char* data() noexcept - { - return buf_; - } - - char const* data() const noexcept - { - return buf_; - } - - std::size_t size() const noexcept - { - return size_; - } - - bool empty() const noexcept - { - return size_ == 0; - } - -private: - std::size_t size_= 0; - char buf_[N]; -}; - - struct basic_parser_base { // limit on the size of the obs-fold buffer @@ -234,7 +182,7 @@ struct basic_parser_base char const* last, string_view& name, string_view& value, - char_buffer& buf, + beast::detail::char_buffer& buf, error_code& ec); BOOST_BEAST_DECL diff --git a/include/boost/beast/http/detail/basic_parser.ipp b/include/boost/beast/http/detail/basic_parser.ipp index ce140eb3..5dd13d4c 100644 --- a/include/boost/beast/http/detail/basic_parser.ipp +++ b/include/boost/beast/http/detail/basic_parser.ipp @@ -495,7 +495,7 @@ parse_field( char const* last, string_view& name, string_view& value, - char_buffer& buf, + beast::detail::char_buffer& buf, error_code& ec) { /* header-field = field-name ":" OWS field-value OWS diff --git a/include/boost/beast/http/impl/basic_parser.ipp b/include/boost/beast/http/impl/basic_parser.ipp index 8474cb5e..a3b0ad6f 100644 --- a/include/boost/beast/http/impl/basic_parser.ipp +++ b/include/boost/beast/http/impl/basic_parser.ipp @@ -404,7 +404,7 @@ parse_fields(char const*& in, string_view name; string_view value; // https://stackoverflow.com/questions/686217/maximum-on-http-header-values - detail::char_buffer buf; + beast::detail::char_buffer buf; auto p = in; for(;;) {