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
This commit is contained in:
Vinnie Falco
2017-12-11 10:06:27 -08:00
parent 96e04022c4
commit d796319476
7 changed files with 79 additions and 48 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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<boost::winapi::DWORD_>(
(std::min<std::uint64_t>)(
(std::min<std::uint64_t>)(r.body_.last_ - r.pos_, sr_.limit()),
(std::min<std::uint64_t>)(w.body_.last_ - w.pos_, sr_.limit()),
(std::numeric_limits<boost::winapi::DWORD_>::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<boost::winapi::DWORD_>(
(std::min<std::uint64_t>)(
(std::min<std::uint64_t>)(r.body_.last_ - r.pos_, sr.limit()),
(std::min<std::uint64_t>)(w.body_.last_ - w.pos_, sr.limit()),
(std::numeric_limits<boost::winapi::DWORD_>::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());
}

View File

@@ -20,7 +20,7 @@ namespace http {
template<bool isRequest, class Body, class Allocator>
parser<isRequest, Body, Allocator>::
parser()
: wr_(m_)
: rd_(m_)
{
}
@@ -30,7 +30,7 @@ parser<isRequest, Body, Allocator>::
parser(Arg1&& arg1, ArgN&&... argn)
: m_(std::forward<Arg1>(arg1),
std::forward<ArgN>(argn)...)
, wr_(m_)
, rd_(m_)
{
m_.clear();
}
@@ -42,7 +42,7 @@ parser(parser<isRequest, OtherBody, Allocator>&& other,
Args&&... args)
: base_type(std::move(other))
, m_(other.release(), std::forward<Args>(args)...)
, wr_(m_)
, rd_(m_)
{
if(other.rd_inited_)
BOOST_THROW_EXCEPTION(std::invalid_argument{

View File

@@ -25,18 +25,18 @@ template<
bool isRequest, class Body, class Fields>
void
serializer<isRequest, Body, Fields>::
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<isRequest, Body, Fields>::
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<isRequest, Body, Fields>::
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<bool,
fwrinit(std::integral_constant<bool,
isRequest>{});
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_)
{

View File

@@ -63,7 +63,7 @@ class parser
parser<isRequest, Body, Allocator>>;
message<isRequest, Body, basic_fields<Allocator>> m_;
typename Body::reader wr_;
typename Body::reader rd_;
bool rd_inited_ = false;
std::function<void(
@@ -376,7 +376,7 @@ private:
boost::optional<std::uint64_t> 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);
}
};

View File

@@ -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<std::size_t, class Visit>
void
@@ -173,8 +173,8 @@ private:
using pcb8_t = buffers_prefix_view<cb8_t const&>;
value_type& m_;
writer rd_;
boost::optional<typename Fields::writer> frd_;
writer wr_;
boost::optional<typename Fields::writer> 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_;
}
};