From d7963194763469c07d61f4870eedb78148c79480 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 11 Dec 2017 10:06:27 -0800 Subject: [PATCH] serializer::reader_impl is deprecated: fix #930 * The function serializer::reader_impl is deprecated and will be removed in a subsequent version. * Some private symbols used in the implementation were also renamed to reflect correct terminology. Actions Required: * Call serializer::writer_impl instead of reader_impl --- CHANGELOG.md | 8 ++++ include/boost/beast/core/detail/config.hpp | 3 ++ .../boost/beast/http/impl/file_body_win32.ipp | 30 +++++++-------- include/boost/beast/http/impl/parser.ipp | 6 +-- include/boost/beast/http/impl/serializer.ipp | 38 +++++++++---------- include/boost/beast/http/parser.hpp | 10 ++--- include/boost/beast/http/serializer.hpp | 32 +++++++++++++--- 7 files changed, 79 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 778bb57c..2b2a3ed0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ Version 150: * handler_ptr tests +API Changes: + +* serializer::reader_impl is deprecated + +Actions Required: + +* Call serializer::writer_impl instead of reader_impl + -------------------------------------------------------------------------------- Version 149: diff --git a/include/boost/beast/core/detail/config.hpp b/include/boost/beast/core/detail/config.hpp index 26deb2df..69be5d19 100644 --- a/include/boost/beast/core/detail/config.hpp +++ b/include/boost/beast/core/detail/config.hpp @@ -54,4 +54,7 @@ # define BOOST_BEAST_FALLTHROUGH __attribute__((fallthrough)) #endif +#define BOOST_BEAST_DEPRECATION_STRING \ + "This is a deprecated interface, #define BOOST_BEAST_ALLOW_DEPRECATED to allow it" + #endif diff --git a/include/boost/beast/http/impl/file_body_win32.ipp b/include/boost/beast/http/impl/file_body_win32.ipp index 2ed08da5..1c748fe0 100644 --- a/include/boost/beast/http/impl/file_body_win32.ipp +++ b/include/boost/beast/http/impl/file_body_win32.ipp @@ -415,11 +415,11 @@ operator()() return detail::async_write_some_impl( sock_, sr_, std::move(*this)); } - auto& r = sr_.reader_impl(); + auto& w = sr_.writer_impl(); boost::winapi::DWORD_ const nNumberOfBytesToWrite = static_cast( (std::min)( - (std::min)(r.body_.last_ - r.pos_, sr_.limit()), + (std::min)(w.body_.last_ - w.pos_, sr_.limit()), (std::numeric_limits::max)())); boost::asio::windows::overlapped_ptr overlapped{ sock_.get_executor().context(), std::move(*this)}; @@ -427,8 +427,8 @@ operator()() // the handler since it is now moved-from. We can still // access simple things like references and built-in types. auto& ov = *overlapped.get(); - ov.Offset = lowPart(r.pos_); - ov.OffsetHigh = highPart(r.pos_); + ov.Offset = lowPart(w.pos_); + ov.OffsetHigh = highPart(w.pos_); auto const bSuccess = ::TransmitFile( sock_.native_handle(), sr_.get().body().file_.native_handle(), @@ -468,10 +468,10 @@ operator()( header_ = false; return (*this)(); } - auto& r = sr_.reader_impl(); - r.pos_ += bytes_transferred; - BOOST_ASSERT(r.pos_ <= r.body_.last_); - if(r.pos_ >= r.body_.last_) + auto& w = sr_.writer_impl(); + w.pos_ += bytes_transferred; + BOOST_ASSERT(w.pos_ <= w.body_.last_); + if(w.pos_ >= w.body_.last_) { sr_.next(ec, null_lambda{}); BOOST_ASSERT(! ec); @@ -512,18 +512,18 @@ write_some( return bytes_transferred; return bytes_transferred; } - auto& r = sr.reader_impl(); - r.body_.file_.seek(r.pos_, ec); + auto& w = sr.writer_impl(); + w.body_.file_.seek(w.pos_, ec); if(ec) return 0; boost::winapi::DWORD_ const nNumberOfBytesToWrite = static_cast( (std::min)( - (std::min)(r.body_.last_ - r.pos_, sr.limit()), + (std::min)(w.body_.last_ - w.pos_, sr.limit()), (std::numeric_limits::max)())); auto const bSuccess = ::TransmitFile( sock.native_handle(), - r.body_.file_.native_handle(), + w.body_.file_.native_handle(), nNumberOfBytesToWrite, 0, nullptr, @@ -536,9 +536,9 @@ write_some( system_category()); return 0; } - r.pos_ += nNumberOfBytesToWrite; - BOOST_ASSERT(r.pos_ <= r.body_.last_); - if(r.pos_ < r.body_.last_) + w.pos_ += nNumberOfBytesToWrite; + BOOST_ASSERT(w.pos_ <= w.body_.last_); + if(w.pos_ < w.body_.last_) { ec.assign(0, ec.category()); } diff --git a/include/boost/beast/http/impl/parser.ipp b/include/boost/beast/http/impl/parser.ipp index 99745da3..0fddf792 100644 --- a/include/boost/beast/http/impl/parser.ipp +++ b/include/boost/beast/http/impl/parser.ipp @@ -20,7 +20,7 @@ namespace http { template parser:: parser() - : wr_(m_) + : rd_(m_) { } @@ -30,7 +30,7 @@ parser:: parser(Arg1&& arg1, ArgN&&... argn) : m_(std::forward(arg1), std::forward(argn)...) - , wr_(m_) + , rd_(m_) { m_.clear(); } @@ -42,7 +42,7 @@ parser(parser&& other, Args&&... args) : base_type(std::move(other)) , m_(other.release(), std::forward(args)...) - , wr_(m_) + , rd_(m_) { if(other.rd_inited_) BOOST_THROW_EXCEPTION(std::invalid_argument{ diff --git a/include/boost/beast/http/impl/serializer.ipp b/include/boost/beast/http/impl/serializer.ipp index 11cf8578..8ce9d8fc 100644 --- a/include/boost/beast/http/impl/serializer.ipp +++ b/include/boost/beast/http/impl/serializer.ipp @@ -25,18 +25,18 @@ template< bool isRequest, class Body, class Fields> void serializer:: -frdinit(std::true_type) +fwrinit(std::true_type) { - frd_.emplace(m_, m_.version(), m_.method()); + fwr_.emplace(m_, m_.version(), m_.method()); } template< bool isRequest, class Body, class Fields> void serializer:: -frdinit(std::false_type) +fwrinit(std::false_type) { - frd_.emplace(m_, m_.version(), m_.result_int()); + fwr_.emplace(m_, m_.version(), m_.result_int()); } template< @@ -59,7 +59,7 @@ template< serializer:: serializer(value_type& m) : m_(m) - , rd_(m_) + , wr_(m_) { } @@ -75,7 +75,7 @@ next(error_code& ec, Visit&& visit) { case do_construct: { - frdinit(std::integral_constant{}); if(m_.chunked()) goto go_init_c; @@ -85,12 +85,12 @@ next(error_code& ec, Visit&& visit) case do_init: { - rd_.init(ec); + wr_.init(ec); if(ec) return; if(split_) goto go_header_only; - auto result = rd_.get(ec); + auto result = wr_.get(ec); if(ec == error::need_more) goto go_header_only; if(ec) @@ -100,7 +100,7 @@ next(error_code& ec, Visit&& visit) more_ = result->second; v_.template emplace<2>( boost::in_place_init, - frd_->get(), + fwr_->get(), result->first); s_ = do_header; BOOST_BEAST_FALLTHROUGH; @@ -111,7 +111,7 @@ next(error_code& ec, Visit&& visit) break; go_header_only: - v_.template emplace<1>(frd_->get()); + v_.template emplace<1>(fwr_->get()); s_ = do_header_only; BOOST_BEAST_FALLTHROUGH; case do_header_only: @@ -124,7 +124,7 @@ next(error_code& ec, Visit&& visit) case do_body + 1: { - auto result = rd_.get(ec); + auto result = wr_.get(ec); if(ec) return; if(! result) @@ -146,12 +146,12 @@ next(error_code& ec, Visit&& visit) BOOST_BEAST_FALLTHROUGH; case do_init_c: { - rd_.init(ec); + wr_.init(ec); if(ec) return; if(split_) goto go_header_only_c; - auto result = rd_.get(ec); + auto result = wr_.get(ec); if(ec == error::need_more) goto go_header_only_c; if(ec) @@ -164,7 +164,7 @@ next(error_code& ec, Visit&& visit) // do it all in one buffer v_.template emplace<7>( boost::in_place_init, - frd_->get(), + fwr_->get(), buffer_size(result->first), boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}, @@ -177,7 +177,7 @@ next(error_code& ec, Visit&& visit) } v_.template emplace<4>( boost::in_place_init, - frd_->get(), + fwr_->get(), buffer_size(result->first), boost::asio::const_buffer{nullptr, 0}, chunk_crlf{}, @@ -192,7 +192,7 @@ next(error_code& ec, Visit&& visit) break; go_header_only_c: - v_.template emplace<1>(frd_->get()); + v_.template emplace<1>(fwr_->get()); s_ = do_header_only_c; case do_header_only_c: do_visit<1>(ec, visit); @@ -204,7 +204,7 @@ next(error_code& ec, Visit&& visit) case do_body_c + 1: { - auto result = rd_.get(ec); + auto result = wr_.get(ec); if(ec) return; if(! result) @@ -309,7 +309,7 @@ consume(std::size_t n) v_.template get<1>().consume(n); if(buffer_size(v_.template get<1>()) > 0) break; - frd_ = boost::none; + fwr_ = boost::none; header_done_ = true; if(! split_) goto go_complete; @@ -353,7 +353,7 @@ consume(std::size_t n) v_.template get<1>().consume(n); if(buffer_size(v_.template get<1>()) > 0) break; - frd_ = boost::none; + fwr_ = boost::none; header_done_ = true; if(! split_) { diff --git a/include/boost/beast/http/parser.hpp b/include/boost/beast/http/parser.hpp index 47e10035..b0799aac 100644 --- a/include/boost/beast/http/parser.hpp +++ b/include/boost/beast/http/parser.hpp @@ -63,7 +63,7 @@ class parser parser>; message> m_; - typename Body::reader wr_; + typename Body::reader rd_; bool rd_inited_ = false; std::function const& content_length, error_code& ec) { - wr_.init(content_length, ec); + rd_.init(content_length, ec); rd_inited_ = true; } @@ -385,7 +385,7 @@ private: string_view body, error_code& ec) { - return wr_.put(boost::asio::buffer( + return rd_.put(boost::asio::buffer( body.data(), body.size()), ec); } @@ -408,14 +408,14 @@ private: { if(cb_b_) return cb_b_(remain, body, ec); - return wr_.put(boost::asio::buffer( + return rd_.put(boost::asio::buffer( body.data(), body.size()), ec); } void on_finish_impl(error_code& ec) { - wr_.finish(ec); + rd_.finish(ec); } }; diff --git a/include/boost/beast/http/serializer.hpp b/include/boost/beast/http/serializer.hpp index 50e58185..640476b8 100644 --- a/include/boost/beast/http/serializer.hpp +++ b/include/boost/beast/http/serializer.hpp @@ -104,8 +104,8 @@ private: do_complete = 120 }; - void frdinit(std::true_type); - void frdinit(std::false_type); + void fwrinit(std::true_type); + void fwrinit(std::false_type); template void @@ -173,8 +173,8 @@ private: using pcb8_t = buffers_prefix_view; value_type& m_; - writer rd_; - boost::optional frd_; + writer wr_; + boost::optional fwr_; beast::detail::variant< cb1_t, cb2_t, cb3_t, cb4_t, cb5_t ,cb6_t, cb7_t, cb8_t> v_; @@ -336,7 +336,7 @@ public: void consume(std::size_t n); - /** Provides low-level access to the associated @b BodyWriter + /** Provides low-level access to the associated @b BodyWriter (DEPRECATED) This function provides access to the instance of the writer associated with the body and created by the serializer @@ -349,7 +349,27 @@ public: writer& reader_impl() { - return rd_; + #ifndef BOOST_BEAST_ALLOW_DEPRECATED + BOOST_STATIC_ASSERT_MSG(sizeof(Body) == 0, + BOOST_BEAST_DEPRECATION_STRING); + #endif + return wr_; + } + + /** Provides low-level access to the associated @b BodyWriter + + This function provides access to the instance of the writer + associated with the body and created by the serializer + upon construction. The behavior of accessing this object + is defined by the specification of the particular writer + and its associated body. + + @return A reference to the writer. + */ + writer& + writer_impl() + { + return wr_; } };