diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:21:30 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:21:30 +0900 |
commit | d6a306e745acfee00e81ccaf3324a2a03516db41 (patch) | |
tree | 145a26368608982f40ebb0f4836185c44abb9ae4 /boost/beast/http/impl | |
parent | 5ce2ccf2f23c6d3de4c79f216f57ca6f2a18ed16 (diff) | |
download | boost-d6a306e745acfee00e81ccaf3324a2a03516db41.tar.gz boost-d6a306e745acfee00e81ccaf3324a2a03516db41.tar.bz2 boost-d6a306e745acfee00e81ccaf3324a2a03516db41.zip |
Imported Upstream version 1.69.0upstream/1.69.0
Diffstat (limited to 'boost/beast/http/impl')
-rw-r--r-- | boost/beast/http/impl/error.ipp | 14 | ||||
-rw-r--r-- | boost/beast/http/impl/field.ipp | 2 | ||||
-rw-r--r-- | boost/beast/http/impl/fields.ipp | 121 | ||||
-rw-r--r-- | boost/beast/http/impl/message.ipp | 24 | ||||
-rw-r--r-- | boost/beast/http/impl/read.ipp | 47 | ||||
-rw-r--r-- | boost/beast/http/impl/verb.ipp | 2 |
6 files changed, 106 insertions, 104 deletions
diff --git a/boost/beast/http/impl/error.ipp b/boost/beast/http/impl/error.ipp index 45075f5c18..b6320cf4c9 100644 --- a/boost/beast/http/impl/error.ipp +++ b/boost/beast/http/impl/error.ipp @@ -94,23 +94,15 @@ public: } }; -inline -error_category const& -get_http_error_category() -{ - static http_error_category const cat{}; - return cat; -} - } // detail inline error_code make_error_code(error ev) { - return error_code{ - static_cast<std::underlying_type<error>::type>(ev), - detail::get_http_error_category()}; + static detail::http_error_category const cat{}; + return error_code{static_cast< + std::underlying_type<error>::type>(ev), cat}; } } // http diff --git a/boost/beast/http/impl/field.ipp b/boost/beast/http/impl/field.ipp index 467a40aeee..b61a0ba8a2 100644 --- a/boost/beast/http/impl/field.ipp +++ b/boost/beast/http/impl/field.ipp @@ -51,7 +51,7 @@ struct field_table { auto p1 = lhs.data(); auto p2 = rhs.data(); - auto pend = lhs.end(); + auto pend = p1 + lhs.size(); char a, b; while(p1 < pend) { diff --git a/boost/beast/http/impl/fields.ipp b/boost/beast/http/impl/fields.ipp index aca61d2f65..f34a8e7471 100644 --- a/boost/beast/http/impl/fields.ipp +++ b/boost/beast/http/impl/fields.ipp @@ -271,19 +271,38 @@ writer(basic_fields const& f, //------------------------------------------------------------------------------ template<class Allocator> +char* basic_fields<Allocator>:: value_type:: -value_type( - field name, - string_view sname, - string_view value) +data() const +{ + return const_cast<char*>( + reinterpret_cast<char const*>( + static_cast<element const*>(this) + 1)); +} + +template<class Allocator> +boost::asio::const_buffer +basic_fields<Allocator>:: +value_type:: +buffer() const +{ + return boost::asio::const_buffer{data(), + static_cast<std::size_t>(off_) + len_ + 2}; +} + +template<class Allocator> +basic_fields<Allocator>:: +value_type:: +value_type(field name, + string_view sname, string_view value) : off_(static_cast<off_t>(sname.size() + 2)) , len_(static_cast<off_t>(value.size())) , f_(name) { //BOOST_ASSERT(name == field::unknown || // iequals(sname, to_string(name))); - char* p = reinterpret_cast<char*>(this + 1); + char* p = data(); p[off_-2] = ':'; p[off_-1] = ' '; p[off_ + len_] = '\r'; @@ -293,7 +312,6 @@ value_type( } template<class Allocator> -inline field basic_fields<Allocator>:: value_type:: @@ -303,39 +321,32 @@ name() const } template<class Allocator> -inline string_view const basic_fields<Allocator>:: value_type:: name_string() const { - return {reinterpret_cast< - char const*>(this + 1), - static_cast<std::size_t>(off_ - 2)}; + return {data(), + static_cast<std::size_t>(off_ - 2)}; } template<class Allocator> -inline string_view const basic_fields<Allocator>:: value_type:: value() const { - return {reinterpret_cast< - char const*>(this + 1) + off_, - static_cast<std::size_t>(len_)}; + return {data() + off_, + static_cast<std::size_t>(len_)}; } template<class Allocator> -inline -boost::asio::const_buffer basic_fields<Allocator>:: -value_type:: -buffer() const +element:: +element(field name, + string_view sname, string_view value) + : value_type(name, sname, value) { - return boost::asio::const_buffer{ - reinterpret_cast<char const*>(this + 1), - static_cast<std::size_t>(off_) + len_ + 2}; } //------------------------------------------------------------------------------ @@ -353,15 +364,15 @@ basic_fields<Allocator>:: template<class Allocator> basic_fields<Allocator>:: basic_fields(Allocator const& alloc) noexcept - : beast::detail::empty_base_optimization<Allocator>(alloc) + : boost::empty_value<Allocator>(boost::empty_init_t(), alloc) { } template<class Allocator> basic_fields<Allocator>:: basic_fields(basic_fields&& other) noexcept - : beast::detail::empty_base_optimization<Allocator>( - std::move(other.member())) + : boost::empty_value<Allocator>(boost::empty_init_t(), + std::move(other.get())) , set_(std::move(other.set_)) , list_(std::move(other.list_)) , method_(boost::exchange(other.method_, {})) @@ -372,9 +383,9 @@ basic_fields(basic_fields&& other) noexcept template<class Allocator> basic_fields<Allocator>:: basic_fields(basic_fields&& other, Allocator const& alloc) - : beast::detail::empty_base_optimization<Allocator>(alloc) + : boost::empty_value<Allocator>(boost::empty_init_t(), alloc) { - if(this->member() != other.member()) + if(this->get() != other.get()) { copy_all(other); other.clear_all(); @@ -391,8 +402,8 @@ basic_fields(basic_fields&& other, Allocator const& alloc) template<class Allocator> basic_fields<Allocator>:: basic_fields(basic_fields const& other) - : beast::detail::empty_base_optimization<Allocator>(alloc_traits:: - select_on_container_copy_construction(other.member())) + : boost::empty_value<Allocator>(boost::empty_init_t(), alloc_traits:: + select_on_container_copy_construction(other.get())) { copy_all(other); } @@ -401,7 +412,7 @@ template<class Allocator> basic_fields<Allocator>:: basic_fields(basic_fields const& other, Allocator const& alloc) - : beast::detail::empty_base_optimization<Allocator>(alloc) + : boost::empty_value<Allocator>(boost::empty_init_t(), alloc) { copy_all(other); } @@ -419,7 +430,7 @@ template<class OtherAlloc> basic_fields<Allocator>:: basic_fields(basic_fields<OtherAlloc> const& other, Allocator const& alloc) - : beast::detail::empty_base_optimization<Allocator>(alloc) + : boost::empty_value<Allocator>(boost::empty_init_t(), alloc) { copy_all(other); } @@ -614,7 +625,7 @@ erase(const_iterator pos) -> auto& e = *next++; set_.erase(e); list_.erase(pos); - delete_element(const_cast<value_type&>(e)); + delete_element(const_cast<element&>(e)); return next; } @@ -634,7 +645,7 @@ erase(string_view name) { std::size_t n =0; set_.erase_and_dispose(name, key_compare{}, - [&](value_type* e) + [&](element* e) { ++n; list_.erase(list_.iterator_to(*e)); @@ -1025,7 +1036,7 @@ set_chunked_impl(bool value) std::basic_string< char, std::char_traits<char>, - A> s{A{this->member()}}; + A> s{A{this->get()}}; #endif s.reserve(it->value().size() + 9); s.append(it->value().data(), it->value().size()); @@ -1062,7 +1073,7 @@ set_chunked_impl(bool value) std::basic_string< char, std::char_traits<char>, - A> s{A{this->member()}}; + A> s{A{this->get()}}; #endif s.reserve(it->value().size()); detail::filter_token_list_last(s, it->value(), @@ -1119,7 +1130,7 @@ set_keep_alive_impl( std::basic_string< char, std::char_traits<char>, - A> s{A{this->member()}}; + A> s{A{this->get()}}; #endif s.reserve(value.size()); detail::keep_alive_impl( @@ -1138,7 +1149,7 @@ auto basic_fields<Allocator>:: new_element(field name, string_view sname, string_view value) -> - value_type& + element& { if(sname.size() + 2 > (std::numeric_limits<off_t>::max)()) @@ -1153,35 +1164,31 @@ new_element(field name, static_cast<off_t>(sname.size() + 2); std::uint16_t const len = static_cast<off_t>(value.size()); - auto a = rebind_type{this->member()}; + auto a = rebind_type{this->get()}; auto const p = alloc_traits::allocate(a, - (sizeof(value_type) + off + len + 2 + sizeof(align_type) - 1) / + (sizeof(element) + off + len + 2 + sizeof(align_type) - 1) / sizeof(align_type)); - // VFALCO allocator can't call the constructor because its private - //alloc_traits::construct(a, p, name, sname, value); - new(p) value_type{name, sname, value}; - return *reinterpret_cast<value_type*>(p); + return *(new(p) element(name, sname, value)); } template<class Allocator> void basic_fields<Allocator>:: -delete_element(value_type& e) +delete_element(element& e) { - auto a = rebind_type{this->member()}; + auto a = rebind_type{this->get()}; auto const n = - (sizeof(value_type) + e.off_ + e.len_ + 2 + sizeof(align_type) - 1) / + (sizeof(element) + e.off_ + e.len_ + 2 + sizeof(align_type) - 1) / sizeof(align_type); - //alloc_traits::destroy(a, &e); - e.~value_type(); - alloc_traits::deallocate(a, - reinterpret_cast<align_type*>(&e), n); + e.~element(); + alloc_traits::deallocate(a, &e, n); + //reinterpret_cast<align_type*>(&e), n); } template<class Allocator> void basic_fields<Allocator>:: -set_element(value_type& e) +set_element(element& e) { auto it = set_.lower_bound( e.name_string(), key_compare{}); @@ -1217,7 +1224,7 @@ realloc_string(string_view& dest, string_view s) return; auto a = typename beast::detail::allocator_traits< Allocator>::template rebind_alloc< - char>(this->member()); + char>(this->get()); char* p = nullptr; if(! s.empty()) { @@ -1246,7 +1253,7 @@ realloc_target( return; auto a = typename beast::detail::allocator_traits< Allocator>::template rebind_alloc< - char>(this->member()); + char>(this->get()); char* p = nullptr; if(! s.empty()) { @@ -1310,7 +1317,7 @@ move_assign(basic_fields& other, std::true_type) target_or_reason_ = other.target_or_reason_; other.method_ = {}; other.target_or_reason_ = {}; - this->member() = other.member(); + this->get() = other.get(); } template<class Allocator> @@ -1320,7 +1327,7 @@ basic_fields<Allocator>:: move_assign(basic_fields& other, std::false_type) { clear_all(); - if(this->member() != other.member()) + if(this->get() != other.get()) { copy_all(other); other.clear_all(); @@ -1343,7 +1350,7 @@ basic_fields<Allocator>:: copy_assign(basic_fields const& other, std::true_type) { clear_all(); - this->member() = other.member(); + this->get() = other.get(); copy_all(other); } @@ -1364,7 +1371,7 @@ basic_fields<Allocator>:: swap(basic_fields& other, std::true_type) { using std::swap; - swap(this->member(), other.member()); + swap(this->get(), other.get()); swap(set_, other.set_); swap(list_, other.list_); swap(method_, other.method_); @@ -1377,7 +1384,7 @@ void basic_fields<Allocator>:: swap(basic_fields& other, std::false_type) { - BOOST_ASSERT(this->member() == other.member()); + BOOST_ASSERT(this->get() == other.get()); using std::swap; swap(set_, other.set_); swap(list_, other.list_); diff --git a/boost/beast/http/impl/message.ipp b/boost/beast/http/impl/message.ipp index 64d96eb6f1..a2a10402f9 100644 --- a/boost/beast/http/impl/message.ipp +++ b/boost/beast/http/impl/message.ipp @@ -197,8 +197,8 @@ template<class... BodyArgs> message<isRequest, Body, Fields>:: message(header_type&& h, BodyArgs&&... body_args) : header_type(std::move(h)) - , beast::detail::empty_base_optimization< - typename Body::value_type>( + , boost::empty_value< + typename Body::value_type>(boost::empty_init_t(), std::forward<BodyArgs>(body_args)...) { } @@ -208,8 +208,8 @@ template<class... BodyArgs> message<isRequest, Body, Fields>:: message(header_type const& h, BodyArgs&&... body_args) : header_type(h) - , beast::detail::empty_base_optimization< - typename Body::value_type>( + , boost::empty_value< + typename Body::value_type>(boost::empty_init_t(), std::forward<BodyArgs>(body_args)...) { } @@ -228,8 +228,8 @@ message<isRequest, Body, Fields>:: message(verb method, string_view target, Version version, BodyArg&& body_arg) : header_type(method, target, version) - , beast::detail::empty_base_optimization< - typename Body::value_type>( + , boost::empty_value< + typename Body::value_type>(boost::empty_init_t(), std::forward<BodyArg>(body_arg)) { } @@ -243,8 +243,8 @@ message( FieldsArg&& fields_arg) : header_type(method, target, version, std::forward<FieldsArg>(fields_arg)) - , beast::detail::empty_base_optimization< - typename Body::value_type>( + , boost::empty_value< + typename Body::value_type>(boost::empty_init_t(), std::forward<BodyArg>(body_arg)) { } @@ -263,8 +263,8 @@ message<isRequest, Body, Fields>:: message(status result, Version version, BodyArg&& body_arg) : header_type(result, version) - , beast::detail::empty_base_optimization< - typename Body::value_type>( + , boost::empty_value< + typename Body::value_type>(boost::empty_init_t(), std::forward<BodyArg>(body_arg)) { } @@ -276,8 +276,8 @@ message(status result, Version version, BodyArg&& body_arg, FieldsArg&& fields_arg) : header_type(result, version, std::forward<FieldsArg>(fields_arg)) - , beast::detail::empty_base_optimization< - typename Body::value_type>( + , boost::empty_value< + typename Body::value_type>(boost::empty_init_t(), std::forward<BodyArg>(body_arg)) { } diff --git a/boost/beast/http/impl/read.ipp b/boost/beast/http/impl/read.ipp index 2ff0c3b128..42ce175d8c 100644 --- a/boost/beast/http/impl/read.ipp +++ b/boost/beast/http/impl/read.ipp @@ -18,9 +18,11 @@ #include <boost/beast/core/handler_ptr.hpp> #include <boost/beast/core/read_size.hpp> #include <boost/beast/core/type_traits.hpp> +#include <boost/beast/core/detail/buffer.hpp> #include <boost/asio/associated_allocator.hpp> #include <boost/asio/associated_executor.hpp> #include <boost/asio/coroutine.hpp> +#include <boost/asio/error.hpp> #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/handler_continuation_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp> @@ -121,8 +123,6 @@ operator()( bool cont) { cont_ = cont; - boost::optional<typename - DynamicBuffer::mutable_buffers_type> mb; BOOST_ASIO_CORO_REENTER(*this) { if(b_.size() == 0) @@ -139,18 +139,22 @@ operator()( break; do_read: - try - { - mb.emplace(b_.prepare( - read_size_or_throw(b_, 65536))); - } - catch(std::length_error const&) + BOOST_ASIO_CORO_YIELD { - ec = error::buffer_overflow; - break; + // VFALCO This was read_size_or_throw + auto const size = read_size(b_, 65536); + if(size == 0) + { + ec = error::buffer_overflow; + goto upcall; + } + auto const mb = + beast::detail::dynamic_buffer_prepare( + b_, size, ec, error::buffer_overflow); + if(ec) + goto upcall; + s_.async_read_some(*mb, std::move(*this)); } - BOOST_ASIO_CORO_YIELD - s_.async_read_some(*mb, std::move(*this)); if(ec == boost::asio::error::eof) { BOOST_ASSERT(bytes_transferred == 0); @@ -513,19 +517,18 @@ read_some( break; } do_read: - boost::optional<typename - DynamicBuffer::mutable_buffers_type> b; - try - { - b.emplace(buffer.prepare( - read_size_or_throw(buffer, 65536))); - } - catch(std::length_error const&) + auto const size = read_size(buffer, 65536); + if(size == 0) { ec = error::buffer_overflow; - return bytes_transferred; + break; } - auto const n = stream.read_some(*b, ec); + auto const mb = + beast::detail::dynamic_buffer_prepare( + buffer, size, ec, error::buffer_overflow); + if(ec) + break; + auto const n = stream.read_some(*mb, ec); if(ec == boost::asio::error::eof) { BOOST_ASSERT(n == 0); diff --git a/boost/beast/http/impl/verb.ipp b/boost/beast/http/impl/verb.ipp index bfd703d05e..36a1734c33 100644 --- a/boost/beast/http/impl/verb.ipp +++ b/boost/beast/http/impl/verb.ipp @@ -127,7 +127,7 @@ string_to_verb(string_view v) ++s; ++p; if(! *s) - return p == sv.end(); + return p == (sv.data() + sv.size()); } }; auto c = v[0]; |