From f4d1936bb2804b1f7a4e7576a0a1d61fd0b9b7bb Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Sun, 23 Oct 2022 11:28:55 +0800 Subject: [PATCH] error_codes use source_location. --- .../_experimental/http/impl/icy_stream.hpp | 2 +- .../beast/_experimental/test/impl/stream.hpp | 14 +++++--- include/boost/beast/core/detail/buffer.hpp | 4 +-- include/boost/beast/core/detail/config.hpp | 12 +++++++ include/boost/beast/core/detail/impl/read.hpp | 2 +- include/boost/beast/core/detect_ssl.hpp | 2 +- .../boost/beast/core/impl/basic_stream.hpp | 8 ++--- .../boost/beast/http/basic_dynamic_body.hpp | 2 +- include/boost/beast/http/basic_file_body.hpp | 2 +- include/boost/beast/http/buffer_body.hpp | 12 ++++--- include/boost/beast/http/empty_body.hpp | 2 +- .../boost/beast/http/impl/chunk_encode.hpp | 20 +++++------ .../boost/beast/http/impl/file_body_win32.hpp | 2 +- include/boost/beast/http/impl/read.hpp | 8 ++--- include/boost/beast/http/parser.hpp | 4 +-- include/boost/beast/http/span_body.hpp | 4 +-- include/boost/beast/http/string_body.hpp | 4 +-- include/boost/beast/http/vector_body.hpp | 4 +-- .../boost/beast/websocket/detail/frame.hpp | 6 ++-- include/boost/beast/websocket/impl/accept.hpp | 19 ++++++---- include/boost/beast/websocket/impl/close.hpp | 6 ++-- .../boost/beast/websocket/impl/handshake.hpp | 6 ++-- include/boost/beast/websocket/impl/ping.hpp | 2 +- include/boost/beast/websocket/impl/read.hpp | 12 ++++--- include/boost/beast/websocket/impl/stream.hpp | 4 ++- .../beast/websocket/impl/stream_impl.hpp | 36 +++++++++---------- include/boost/beast/websocket/impl/write.hpp | 2 +- 27 files changed, 117 insertions(+), 84 deletions(-) diff --git a/include/boost/beast/_experimental/http/impl/icy_stream.hpp b/include/boost/beast/_experimental/http/impl/icy_stream.hpp index 308d61a9..e207f935 100644 --- a/include/boost/beast/_experimental/http/impl/icy_stream.hpp +++ b/include/boost/beast/_experimental/http/impl/icy_stream.hpp @@ -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); diff --git a/include/boost/beast/_experimental/test/impl/stream.hpp b/include/boost/beast/_experimental/test/impl/stream.hpp index 57025833..af5ed67a 100644 --- a/include/boost/beast/_experimental/test/impl/stream.hpp +++ b/include/boost/beast/_experimental/test/impl/stream.hpp @@ -83,7 +83,9 @@ class basic_stream::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 lock(sp->m); @@ -98,7 +100,7 @@ class basic_stream::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 = {}; diff --git a/include/boost/beast/core/detail/buffer.hpp b/include/boost/beast/core/detail/buffer.hpp index b78bdbe1..3a240a52 100644 --- a/include/boost/beast/core/detail/buffer.hpp +++ b/include/boost/beast/core/detail/buffer.hpp @@ -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 #include #include +#include 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 diff --git a/include/boost/beast/core/detail/impl/read.hpp b/include/boost/beast/core/detail/impl/read.hpp index 842af609..172bed23 100644 --- a/include/boost/beast/core/detail/impl/read.hpp +++ b/include/boost/beast/core/detail/impl/read.hpp @@ -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_); } diff --git a/include/boost/beast/core/detect_ssl.hpp b/include/boost/beast/core/detect_ssl.hpp index 272535f5..b641b3ff 100644 --- a/include/boost/beast/core/detect_ssl.hpp +++ b/include/boost/beast/core/detect_ssl.hpp @@ -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. diff --git a/include/boost/beast/core/impl/basic_stream.hpp b/include/boost/beast/core/impl/basic_stream.hpp index 73fb9169..f0a0645e 100644 --- a/include/boost/beast/core/impl/basic_stream.hpp +++ b/include/boost/beast/core/impl/basic_stream.hpp @@ -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; } } diff --git a/include/boost/beast/http/basic_dynamic_body.hpp b/include/boost/beast/http/basic_dynamic_body.hpp index f49c50da..fb5f8d43 100644 --- a/include/boost/beast/http/basic_dynamic_body.hpp +++ b/include/boost/beast/http/basic_dynamic_body.hpp @@ -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 = diff --git a/include/boost/beast/http/basic_file_body.hpp b/include/boost/beast/http/basic_file_body.hpp index 25ea2685..e57ae01b 100644 --- a/include/boost/beast/http/basic_file_body.hpp +++ b/include/boost/beast/http/basic_file_body.hpp @@ -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; } diff --git a/include/boost/beast/http/buffer_body.hpp b/include/boost/beast/http/buffer_body.hpp index 8988c232..43662229 100644 --- a/include/boost/beast/http/buffer_body.hpp +++ b/include/boost/beast/http/buffer_body.hpp @@ -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; diff --git a/include/boost/beast/http/empty_body.hpp b/include/boost/beast/http/empty_body.hpp index 40ea2461..17576a11 100644 --- a/include/boost/beast/http/empty_body.hpp +++ b/include/boost/beast/http/empty_body.hpp @@ -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; } diff --git a/include/boost/beast/http/impl/chunk_encode.hpp b/include/boost/beast/http/impl/chunk_encode.hpp index 0272e3ab..b057571f 100644 --- a/include/boost/beast/http/impl/chunk_encode.hpp +++ b/include/boost/beast/http/impl/chunk_encode.hpp @@ -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; } } diff --git a/include/boost/beast/http/impl/file_body_win32.hpp b/include/boost/beast/http/impl/file_body_win32.hpp index e798a7b6..02bd5222 100644 --- a/include/boost/beast/http/impl/file_body_win32.hpp +++ b/include/boost/beast/http/impl/file_body_win32.hpp @@ -162,7 +162,7 @@ struct basic_file_body 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); diff --git a/include/boost/beast/http/impl/read.hpp b/include/boost/beast/http/impl/read.hpp index 3ddede68..8cf4c19b 100644 --- a/include/boost/beast/http/impl/read.hpp +++ b/include/boost/beast/http/impl/read.hpp @@ -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& 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& 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) diff --git a/include/boost/beast/http/parser.hpp b/include/boost/beast/http/parser.hpp index 9b0523f7..f780ea6a 100644 --- a/include/boost/beast/http/parser.hpp +++ b/include/boost/beast/http/parser.hpp @@ -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; diff --git a/include/boost/beast/http/span_body.hpp b/include/boost/beast/http/span_body.hpp index 72b9ef5d..344d8d85 100644 --- a/include/boost/beast/http/span_body.hpp +++ b/include/boost/beast/http/span_body.hpp @@ -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 = {}; diff --git a/include/boost/beast/http/string_body.hpp b/include/boost/beast/http/string_body.hpp index aeeefcc4..b3063122 100644 --- a/include/boost/beast/http/string_body.hpp +++ b/include/boost/beast/http/string_body.hpp @@ -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; } diff --git a/include/boost/beast/http/vector_body.hpp b/include/boost/beast/http/vector_body.hpp index c599e162..4665b00b 100644 --- a/include/boost/beast/http/vector_body.hpp +++ b/include/boost/beast/http/vector_body.hpp @@ -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; } diff --git a/include/boost/beast/websocket/detail/frame.hpp b/include/boost/beast/websocket/detail/frame.hpp index f217e04a..fc2b1643 100644 --- a/include/boost/beast/websocket/detail/frame.hpp +++ b/include/boost/beast/websocket/detail/frame.hpp @@ -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 = {}; diff --git a/include/boost/beast/websocket/impl/accept.hpp b/include/boost/beast/websocket/impl/accept.hpp index 4f8dbcc7..c537a20c 100644 --- a/include/boost/beast/websocket/impl/accept.hpp +++ b/include/boost/beast/websocket/impl/accept.hpp @@ -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 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); diff --git a/include/boost/beast/websocket/impl/close.hpp b/include/boost/beast/websocket/impl/close.hpp index 4e42c366..d32d9830 100644 --- a/include/boost/beast/websocket/impl/close.hpp +++ b/include/boost/beast/websocket/impl/close.hpp @@ -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 diff --git a/include/boost/beast/websocket/impl/handshake.hpp b/include/boost/beast/websocket/impl/handshake.hpp index 4ad9e369..c7f7bee9 100644 --- a/include/boost/beast/websocket/impl/handshake.hpp +++ b/include/boost/beast/websocket/impl/handshake.hpp @@ -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); } } } diff --git a/include/boost/beast/websocket/impl/ping.hpp b/include/boost/beast/websocket/impl/ping.hpp index 735c8543..dd1233ec 100644 --- a/include/boost/beast/websocket/impl/ping.hpp +++ b/include/boost/beast/websocket/impl/ping.hpp @@ -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; diff --git a/include/boost/beast/websocket/impl/read.hpp b/include/boost/beast/websocket/impl/read.hpp index 383d4cb1..f1f9ac87 100644 --- a/include/boost/beast/websocket/impl/read.hpp +++ b/include/boost/beast/websocket/impl/read.hpp @@ -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_); } diff --git a/include/boost/beast/websocket/impl/stream.hpp b/include/boost/beast/websocket/impl/stream.hpp index 5f5a190d..f71c9c84 100644 --- a/include/boost/beast/websocket/impl/stream.hpp +++ b/include/boost/beast/websocket/impl/stream.hpp @@ -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 diff --git a/include/boost/beast/websocket/impl/stream_impl.hpp b/include/boost/beast/websocket/impl/stream_impl.hpp index 4a8232b1..b3042e33 100644 --- a/include/boost/beast/websocket/impl/stream_impl.hpp +++ b/include/boost/beast/websocket/impl/stream_impl.hpp @@ -342,7 +342,7 @@ struct stream::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::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::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; } } diff --git a/include/boost/beast/websocket/impl/write.hpp b/include/boost/beast/websocket/impl/write.hpp index 4cfc4b1a..217a8ae3 100644 --- a/include/boost/beast/websocket/impl/write.hpp +++ b/include/boost/beast/websocket/impl/write.hpp @@ -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_); }