error_codes use source_location.

This commit is contained in:
Klemens Morgenstern
2022-10-23 11:28:55 +08:00
committed by Klemens Morgenstern
parent 9473c10dde
commit f4d1936bb2
27 changed files with 117 additions and 84 deletions

View File

@@ -157,7 +157,7 @@ public:
net::mutable_buffer{},
std::move(*this));
}
ec = ec_;
BOOST_BEAST_ASSIGN_EC(ec, ec_);
bytes_transferred = n_;
}
this->complete_now(ec, bytes_transferred);

View File

@@ -83,7 +83,9 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
std::size_t bytes_transferred = 0;
auto sp = wp_.lock();
if(! sp)
ec = net::error::operation_aborted;
{
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
}
if(! ec)
{
std::lock_guard<std::mutex> lock(sp->m);
@@ -98,7 +100,7 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
}
else if (buffer_bytes(b_) > 0)
{
ec = net::error::eof;
BOOST_BEAST_ASSIGN_EC(ec, net::error::eof);
}
}
@@ -311,7 +313,7 @@ read_some(MutableBufferSequence const& buffers,
// deliver error
BOOST_ASSERT(in_->code != detail::stream_status::ok);
ec = net::error::eof;
BOOST_BEAST_ASSIGN_EC(ec, net::error::eof);
return 0;
}
@@ -382,7 +384,7 @@ write_some(
auto out = out_.lock();
if(! out)
{
ec = net::error::connection_reset;
BOOST_BEAST_ASSIGN_EC(ec, net::error::connection_reset);
return 0;
}
@@ -441,7 +443,9 @@ async_teardown(
s.close();
if( s.in_->fc &&
s.in_->fc->fail(ec))
ec = net::error::eof;
{
BOOST_BEAST_ASSIGN_EC(ec, net::error::eof);
}
else
ec = {};

View File

@@ -34,7 +34,7 @@ dynamic_buffer_prepare_noexcept(
if(buffer.max_size() - buffer.size() < size)
{
// length error
ec = ev;
BOOST_BEAST_ASSIGN_EC(ec, ev);
return boost::none;
}
boost::optional<typename
@@ -67,7 +67,7 @@ dynamic_buffer_prepare(
}
catch(std::length_error const&)
{
ec = ev;
BOOST_BEAST_ASSIGN_EC(ec, ev);
}
return boost::none;

View File

@@ -15,6 +15,7 @@
#include <boost/version.hpp>
#include <boost/core/ignore_unused.hpp>
#include <boost/static_assert.hpp>
#include <boost/preprocessor/cat.hpp>
namespace boost {
namespace asio
@@ -101,4 +102,15 @@ namespace net = boost::asio;
#define BOOST_BEAST_ASYNC_TPARAM2 BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::beast::error_code, ::std::size_t))
#endif
#ifdef BOOST_BEAST_NO_SOURCE_LOCATION
#define BOOST_BEAST_ASSIGN_EC(ec, error) ec.assign(error)
#else
#define BOOST_BEAST_ASSIGN_EC(ec, error) \
static constexpr auto BOOST_PP_CAT(loc_, __LINE__) ((BOOST_CURRENT_LOCATION)); \
ec.assign(error, & BOOST_PP_CAT(loc_, __LINE__) )
#endif
#endif

View File

@@ -96,7 +96,7 @@ public:
BOOST_ASIO_CORO_YIELD
s_.async_read_some(
b_.prepare(0), std::move(*this));
ec = ec_;
BOOST_BEAST_ASSIGN_EC(ec, ec_);
}
this->complete_now(ec, total_);
}

View File

@@ -647,7 +647,7 @@ operator()(error_code ec, std::size_t bytes_transferred, bool cont)
}
// Restore the saved error code
ec = ec_;
BOOST_BEAST_ASSIGN_EC(ec, ec_);
}
// Invoke the final handler.

View File

@@ -326,7 +326,7 @@ public:
if(state().timer.expiry() <= clock_type::now())
{
impl_->close();
ec = beast::error::timeout;
BOOST_BEAST_ASSIGN_EC(ec, beast::error::timeout);
}
goto upcall;
}
@@ -371,7 +371,7 @@ public:
if(state().timeout)
{
// yes, socket already closed
ec = beast::error::timeout;
BOOST_BEAST_ASSIGN_EC(ec, beast::error::timeout);
state().timeout = false;
}
goto upcall;
@@ -407,7 +407,7 @@ public:
if(state().timeout)
{
// yes, socket already closed
ec = beast::error::timeout;
BOOST_BEAST_ASSIGN_EC(ec, beast::error::timeout);
state().timeout = false;
}
}
@@ -566,7 +566,7 @@ public:
if(state().timeout)
{
// yes, socket already closed
ec = beast::error::timeout;
BOOST_BEAST_ASSIGN_EC(ec, beast::error::timeout);
state().timeout = false;
}
}

View File

@@ -92,7 +92,7 @@ struct basic_dynamic_body
auto const n = buffer_bytes(buffers);
if(beast::detail::sum_exceeds(body_.size(), n, body_.max_size()))
{
ec = error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
return 0;
}
auto const mb =

View File

@@ -367,7 +367,7 @@ get(error_code& ec) ->
if (nread == 0)
{
ec = error::short_read;
BOOST_BEAST_ASSIGN_EC(ec, error::short_read);
return boost::none;
}

View File

@@ -124,7 +124,7 @@ struct buffer_body
{
if(! body_.data)
{
ec = error::need_buffer;
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffer);
return 0;
}
auto const bytes_transferred =
@@ -136,7 +136,9 @@ struct buffer_body
if(bytes_transferred == buffer_bytes(buffers))
ec = {};
else
ec = error::need_buffer;
{
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffer);
}
return bytes_transferred;
}
@@ -186,7 +188,7 @@ struct buffer_body
if(body_.more)
{
toggle_ = false;
ec = error::need_buffer;
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffer);
}
else
{
@@ -202,7 +204,9 @@ struct buffer_body
body_.data, body_.size}, body_.more}};
}
if(body_.more)
ec = error::need_buffer;
{
BOOST_BEAST_ASSIGN_EC(ec, error::need_buffer);
}
else
ec = {};
return boost::none;

View File

@@ -78,7 +78,7 @@ struct empty_body
put(ConstBufferSequence const&,
error_code& ec)
{
ec = error::unexpected_body;
BOOST_BEAST_ASSIGN_EC(ec, error::unexpected_body);
return 0;
}

View File

@@ -399,7 +399,7 @@ loop:
++it;
if(it == last)
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
if(*it != ' ' && *it != '\t')
@@ -409,7 +409,7 @@ loop:
// ';'
if(*it != ';')
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
semi:
@@ -419,7 +419,7 @@ semi:
{
if(it == last)
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
if(*it != ' ' && *it != '\t')
@@ -430,7 +430,7 @@ semi:
{
if(! detail::is_token_char(*it))
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
auto const first = it;
@@ -455,7 +455,7 @@ semi:
++it;
if(it == last)
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
}
@@ -466,7 +466,7 @@ semi:
}
if(*it != '=')
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
++it; // skip '='
@@ -475,7 +475,7 @@ semi:
{
if(it == last)
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
if(*it != ' ' && *it != '\t')
@@ -488,7 +488,7 @@ semi:
// token
if(! detail::is_token_char(*it))
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
auto const first = it;
@@ -514,7 +514,7 @@ semi:
{
if(it == last)
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
if(*it == '"')
@@ -524,7 +524,7 @@ semi:
++it;
if(it == last)
{
ec = error::bad_chunk_extension;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
return it;
}
}

View File

@@ -162,7 +162,7 @@ struct basic_file_body<file_win32>
return boost::none;
if (nread == 0)
{
ec = error::short_read;
BOOST_BEAST_ASSIGN_EC(ec, error::short_read);
return boost::none;
}
BOOST_ASSERT(nread != 0);

View File

@@ -199,7 +199,7 @@ public:
auto const size = read_size(b_, 65536);
if(size == 0)
{
ec = error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
goto upcall;
}
auto const mb =
@@ -228,7 +228,7 @@ public:
BOOST_ASSERT(p_.is_done());
goto upcall;
}
ec = error::end_of_stream;
BOOST_BEAST_ASSIGN_EC(ec, error::end_of_stream);
break;
}
if(ec)
@@ -337,7 +337,7 @@ read_some(SyncReadStream& s, DynamicBuffer& b, basic_parser<isRequest>& p, error
auto const size = read_size(b, 65536);
if(size == 0)
{
ec = error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
return total;
}
auto const mb =
@@ -362,7 +362,7 @@ read_some(SyncReadStream& s, DynamicBuffer& b, basic_parser<isRequest>& p, error
BOOST_ASSERT(p.is_done());
return total;
}
ec = error::end_of_stream;
BOOST_BEAST_ASSIGN_EC(ec, error::end_of_stream);
break;
}
if(ec)

View File

@@ -345,7 +345,7 @@ private:
BOOST_ASSERT(! used_);
if(used_)
{
ec = error::stale_parser;
BOOST_BEAST_ASSIGN_EC(ec, error::stale_parser);
return;
}
used_ = true;
@@ -395,7 +395,7 @@ private:
BOOST_ASSERT(! used_);
if(used_)
{
ec = error::stale_parser;
BOOST_BEAST_ASSIGN_EC(ec, error::stale_parser);
return;
}
used_ = true;

View File

@@ -87,7 +87,7 @@ public:
{
if(length && *length > body_.size())
{
ec = error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
return;
}
ec = {};
@@ -102,7 +102,7 @@ public:
auto const len = body_.size();
if(n > len)
{
ec = error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
return 0;
}
ec = {};

View File

@@ -96,7 +96,7 @@ public:
{
if(*length > body_.max_size())
{
ec = error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
return;
}
body_.reserve(beast::detail::clamp(*length));
@@ -113,7 +113,7 @@ public:
auto const size = body_.size();
if (extra > body_.max_size() - size)
{
ec = error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
return 0;
}

View File

@@ -89,7 +89,7 @@ public:
{
if(*length > body_.max_size())
{
ec = error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
return;
}
body_.reserve(beast::detail::clamp(*length));
@@ -106,7 +106,7 @@ public:
auto const len = body_.size();
if (n > body_.max_size() - len)
{
ec = error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
return 0;
}

View File

@@ -209,7 +209,7 @@ read_close(
if(n == 1)
{
// invalid payload size == 1
ec = error::bad_close_size;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_close_size);
return;
}
@@ -225,7 +225,7 @@ read_close(
if(! is_valid_close_code(cr.code))
{
// invalid close code
ec = error::bad_close_code;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_close_code);
return;
}
@@ -233,7 +233,7 @@ read_close(
cr.reason.data(), cr.reason.size()))
{
// not valid utf-8
ec = error::bad_close_payload;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_close_payload);
return;
}
ec = {};

View File

@@ -215,7 +215,7 @@ public:
auto sp = wp_.lock();
if(! sp)
{
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
return this->complete(cont, ec);
}
auto& impl = *sp;
@@ -247,7 +247,10 @@ public:
if(impl.check_stop_now(ec))
goto upcall;
if(! ec)
ec = result_;
{
BOOST_BEAST_ASSIGN_EC(ec, result_);
BOOST_BEAST_ASSIGN_EC(ec, result_);
}
if(! ec)
{
impl.do_pmd_config(res_);
@@ -311,7 +314,7 @@ public:
auto sp = wp_.lock();
if(! sp)
{
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
return this->complete(cont, ec);
}
auto& impl = *sp;
@@ -334,7 +337,9 @@ public:
impl.rd_buf, p_, std::move(*this));
}
if(ec == http::error::end_of_stream)
ec = error::closed;
{
BOOST_BEAST_ASSIGN_EC(ec, error::closed);
}
if(impl.check_stop_now(ec))
goto upcall;
@@ -456,7 +461,7 @@ do_accept(
http::write(impl_->stream(), res, ec);
if(ec)
return;
ec = result;
BOOST_BEAST_ASSIGN_EC(ec, result);
if(ec)
{
// VFALCO TODO Respect keep alive setting, perform
@@ -488,7 +493,9 @@ do_accept(
http::request_parser<http::empty_body> p;
http::read(next_layer(), impl_->rd_buf, p, ec);
if(ec == http::error::end_of_stream)
ec = error::closed;
{
BOOST_BEAST_ASSIGN_EC(ec, error::closed);
}
if(ec)
return;
do_accept(p.get(), decorator, ec);

View File

@@ -76,7 +76,7 @@ public:
auto sp = wp_.lock();
if(! sp)
{
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
return this->complete(cont, ec);
}
auto& impl = *sp;
@@ -260,7 +260,9 @@ public:
ec = {};
}
if(! ec)
ec = ev_;
{
BOOST_BEAST_ASSIGN_EC(ec, ev_);
}
if(ec)
impl.change_status(status::failed);
else

View File

@@ -93,7 +93,7 @@ public:
auto sp = wp_.lock();
if(! sp)
{
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
return this->complete(cont, ec);
}
auto& impl = *sp;
@@ -162,7 +162,7 @@ public:
}
else
{
ec = http::error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, http::error::buffer_overflow);
}
}
@@ -271,7 +271,7 @@ do_handshake(
}
else
{
ec = http::error::buffer_overflow;
BOOST_BEAST_ASSIGN_EC(ec, http::error::buffer_overflow);
}
}
}

View File

@@ -72,7 +72,7 @@ public:
auto sp = wp_.lock();
if(! sp)
{
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
return this->complete(cont, ec);
}
auto& impl = *sp;

View File

@@ -87,7 +87,7 @@ public:
auto sp = wp_.lock();
if(! sp)
{
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
bytes_written_ = 0;
return this->complete(cont, ec, bytes_written_);
}
@@ -136,7 +136,7 @@ public:
// a `close_op` wrote a close frame
BOOST_ASSERT(impl.wr_close);
BOOST_ASSERT(impl.status_ != status::open);
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
goto upcall;
}
else
@@ -145,7 +145,7 @@ public:
if( impl.status_ == status::closed ||
impl.status_ == status::failed)
{
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
goto upcall;
}
}
@@ -691,7 +691,9 @@ public:
ec = {};
}
if(! ec)
ec = result_;
{
BOOST_BEAST_ASSIGN_EC(ec, result_);
}
if(ec && ec != error::closed)
impl.change_status(status::failed);
else
@@ -756,7 +758,7 @@ public:
auto sp = wp_.lock();
if(! sp)
{
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
bytes_written_ = 0;
return this->complete(cont, ec, bytes_written_);
}

View File

@@ -352,7 +352,9 @@ do_fail(
ec = {};
}
if(! ec)
ec = ev;
{
BOOST_BEAST_ASSIGN_EC(ec, ev);
}
if(ec && ec != error::closed)
impl_->change_status(status::failed);
else

View File

@@ -342,7 +342,7 @@ struct stream<NextLayer, deflateSupported>::impl_type
if(timed_out)
{
timed_out = false;
ec = beast::error::timeout;
BOOST_BEAST_ASSIGN_EC(ec, beast::error::timeout);
return true;
}
@@ -351,7 +351,7 @@ struct stream<NextLayer, deflateSupported>::impl_type
status_ == status::failed)
{
//BOOST_ASSERT(ec_delivered);
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
return true;
}
@@ -363,7 +363,7 @@ struct stream<NextLayer, deflateSupported>::impl_type
if(ec_delivered)
{
// No, so abort
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
return true;
}
@@ -653,7 +653,7 @@ on_response(
auto const err =
[&](error e)
{
ec = e;
BOOST_BEAST_ASSIGN_EC(ec, e);
};
if(res.result() != http::status::switching_protocols)
return err(error::upgrade_declined);
@@ -747,14 +747,14 @@ parse_fh(
if(rd_cont)
{
// new data frame when continuation expected
ec = error::bad_data_frame;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_data_frame);
return false;
}
if(fh.rsv2 || fh.rsv3 ||
! this->rd_deflated(fh.rsv1))
{
// reserved bits not cleared
ec = error::bad_reserved_bits;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_reserved_bits);
return false;
}
break;
@@ -763,13 +763,13 @@ parse_fh(
if(! rd_cont)
{
// continuation without an active message
ec = error::bad_continuation;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_continuation);
return false;
}
if(fh.rsv1 || fh.rsv2 || fh.rsv3)
{
// reserved bits not cleared
ec = error::bad_reserved_bits;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_reserved_bits);
return false;
}
break;
@@ -778,25 +778,25 @@ parse_fh(
if(detail::is_reserved(fh.op))
{
// reserved opcode
ec = error::bad_opcode;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_opcode);
return false;
}
if(! fh.fin)
{
// fragmented control message
ec = error::bad_control_fragment;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_control_fragment);
return false;
}
if(fh.len > 125)
{
// invalid length for control message
ec = error::bad_control_size;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_control_size);
return false;
}
if(fh.rsv1 || fh.rsv2 || fh.rsv3)
{
// reserved bits not cleared
ec = error::bad_reserved_bits;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_reserved_bits);
return false;
}
break;
@@ -804,13 +804,13 @@ parse_fh(
if(role == role_type::server && ! fh.mask)
{
// unmasked frame from client
ec = error::bad_unmasked_frame;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_unmasked_frame);
return false;
}
if(role == role_type::client && fh.mask)
{
// masked frame from server
ec = error::bad_masked_frame;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_masked_frame);
return false;
}
if(detail::is_control(fh.op) &&
@@ -833,7 +833,7 @@ parse_fh(
if(fh.len < 126)
{
// length not canonical
ec = error::bad_size;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_size);
return false;
}
break;
@@ -848,7 +848,7 @@ parse_fh(
if(fh.len < 65536)
{
// length not canonical
ec = error::bad_size;
BOOST_BEAST_ASSIGN_EC(ec, error::bad_size);
return false;
}
break;
@@ -881,7 +881,7 @@ parse_fh(
std::uint64_t>::max)() - fh.len)
{
// message size exceeds configured limit
ec = error::message_too_big;
BOOST_BEAST_ASSIGN_EC(ec, error::message_too_big);
return false;
}
}
@@ -891,7 +891,7 @@ parse_fh(
rd_size, fh.len, rd_msg_max))
{
// message size exceeds configured limit
ec = error::message_too_big;
BOOST_BEAST_ASSIGN_EC(ec, error::message_too_big);
return false;
}
}

View File

@@ -162,7 +162,7 @@ operator()(
auto sp = wp_.lock();
if(! sp)
{
ec = net::error::operation_aborted;
BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted);
bytes_transferred_ = 0;
return this->complete(cont, ec, bytes_transferred_);
}