Skip to content

Commit

Permalink
serializer::reader_impl is deprecated:
Browse files Browse the repository at this point in the history
fix boostorg#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
  • Loading branch information
vinniefalco committed Dec 11, 2017
1 parent cafaa12 commit 790b8e9
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 48 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions include/boost/beast/core/detail/config.hpp
Expand Up @@ -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=1 to allow it"

#endif
30 changes: 15 additions & 15 deletions include/boost/beast/http/impl/file_body_win32.ipp
Expand Up @@ -415,20 +415,20 @@ 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)};
// Note that we have moved *this, so we cannot access
// 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(),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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());
}
Expand Down
6 changes: 3 additions & 3 deletions include/boost/beast/http/impl/parser.ipp
Expand Up @@ -20,7 +20,7 @@ namespace http {
template<bool isRequest, class Body, class Allocator>
parser<isRequest, Body, Allocator>::
parser()
: wr_(m_)
: rd_(m_)
{
}

Expand All @@ -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();
}
Expand All @@ -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{
Expand Down
38 changes: 19 additions & 19 deletions include/boost/beast/http/impl/serializer.ipp
Expand Up @@ -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<
Expand All @@ -59,7 +59,7 @@ template<
serializer<isRequest, Body, Fields>::
serializer(value_type& m)
: m_(m)
, rd_(m_)
, wr_(m_)
{
}

Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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{},
Expand All @@ -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{},
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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_)
{
Expand Down
10 changes: 5 additions & 5 deletions include/boost/beast/http/parser.hpp
Expand Up @@ -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(
Expand Down Expand Up @@ -376,7 +376,7 @@ class parser
boost::optional<std::uint64_t> const& content_length,
error_code& ec)
{
wr_.init(content_length, ec);
rd_.init(content_length, ec);
rd_inited_ = true;
}

Expand All @@ -385,7 +385,7 @@ class parser
string_view body,
error_code& ec)
{
return wr_.put(boost::asio::buffer(
return rd_.put(boost::asio::buffer(
body.data(), body.size()), ec);
}

Expand All @@ -408,14 +408,14 @@ class parser
{
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);
}
};

Expand Down
32 changes: 26 additions & 6 deletions include/boost/beast/http/serializer.hpp
Expand Up @@ -104,8 +104,8 @@ class serializer
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
Expand Down Expand Up @@ -173,8 +173,8 @@ class serializer
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_;
Expand Down Expand Up @@ -336,7 +336,7 @@ class serializer
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
Expand All @@ -349,7 +349,27 @@ class serializer
writer&
reader_impl()
{
return rd_;
#if ! 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_;
}
};

Expand Down

0 comments on commit 790b8e9

Please sign in to comment.