From ca109693fb0b7d89add059052808371ecdd7c2f4 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 13 Jun 2017 07:08:52 -0700 Subject: [PATCH] Reset error codes fix #478 --- .github/ISSUE_TEMPLATE.md | 2 + CHANGELOG.md | 1 + doc/concept/BodyReader.qbk | 17 ++++++--- doc/concept/BodyWriter.qbk | 15 ++++++-- examples/doc_core_samples.hpp | 5 ++- examples/doc_http_samples.hpp | 11 ++++++ examples/file_body.hpp | 15 ++++++++ extras/beast/test/fail_counter.hpp | 1 + extras/beast/test/pipe_stream.hpp | 3 ++ extras/beast/test/string_iostream.hpp | 9 ++++- extras/beast/test/string_istream.hpp | 9 ++++- extras/beast/test/string_ostream.hpp | 4 +- .../beast/core/impl/buffered_read_stream.ipp | 4 ++ include/beast/http/basic_parser.hpp | 7 +++- include/beast/http/buffer_body.hpp | 20 ++++++++-- include/beast/http/detail/basic_parser.hpp | 20 ++++++++++ include/beast/http/dynamic_body.hpp | 14 +++++-- include/beast/http/empty_body.hpp | 13 +++++-- include/beast/http/impl/basic_parser.ipp | 14 ++++++- include/beast/http/impl/read.ipp | 20 +++++++--- include/beast/http/impl/serializer.ipp | 3 +- include/beast/http/impl/write.ipp | 37 ++++++++++++++----- include/beast/http/parser.hpp | 15 ++++++-- include/beast/http/string_body.hpp | 14 +++++-- include/beast/http/string_view_body.hpp | 7 +++- .../beast/websocket/detail/pmd_extension.hpp | 1 + include/beast/websocket/impl/stream.ipp | 3 +- test/http/doc_http_samples.cpp | 1 + test/http/doc_snippets.cpp | 4 ++ test/http/parser_bench.cpp | 20 +++++++--- test/http/test_parser.hpp | 16 ++++++++ test/http/write.cpp | 18 ++++++--- 32 files changed, 276 insertions(+), 67 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 682516a7..b342a0d7 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,3 +1,5 @@ +PLEASE DON'T FORGET TO "STAR" THIS REPOSITORY :) + When reporting a bug please include the following: ### Version of Beast diff --git a/CHANGELOG.md b/CHANGELOG.md index f01487c6..d69cef6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Version 56: * Call on_chunk when the extension is empty * HTTP/1.1 is the default version * Try harder to find Boost (cmake) +* Reset error codes -------------------------------------------------------------------------------- diff --git a/doc/concept/BodyReader.qbk b/doc/concept/BodyReader.qbk index 0d320085..4aa80bae 100644 --- a/doc/concept/BodyReader.qbk +++ b/doc/concept/BodyReader.qbk @@ -72,9 +72,9 @@ In this table: [`a.init(ec)`] [] [ - Called immediately after construction. If the function sets an - error code in `ec`, the serialization is aborted and the error - is propagated to the caller. + Called immediately after construction. + The function will ensure that `!ec` is `true` if there was + no error or set to the appropriate error code if there was one. ] ][ [`a.get(ec)`] @@ -90,6 +90,8 @@ In this table: if there may be additional buffers returned on a subsequent call, or `false` if the buffer returned on this call is the last buffer representing the body. + The function will ensure that `!ec` is `true` if there was + no error or set to the appropriate error code if there was one. ] ][ [`a.finish(ec)`] @@ -97,7 +99,8 @@ In this table: [ This function is called after the reader indicates there are no more buffers remaining. - If `ec` is set, the error will be propagated to the caller. + The function will ensure that `!ec` is `true` if there was + no error or set to the appropriate error code if there was one. ] ][ [`is_body_reader`] @@ -146,7 +149,11 @@ public: @param ec Set to the error, if any occurred. */ void - init(error_code& ec); + init(error_code& ec) + { + // The specification requires this to indicate "no error" + ec = {}; + } /** Returns the next buffer in the body. diff --git a/doc/concept/BodyWriter.qbk b/doc/concept/BodyWriter.qbk index e7ff49d1..e8c22fc4 100644 --- a/doc/concept/BodyWriter.qbk +++ b/doc/concept/BodyWriter.qbk @@ -58,7 +58,8 @@ In the table below: be set to the content length of the body if known, otherwise `length` will be equal to `boost::none`. Implementations of [*BodyWriter] may use this information to optimize allocation. - If `ec` is set, the error will be propagated to the caller. + The function will ensure that `!ec` is `true` if there was + no error or set to the appropriate error code if there was one. ] ][ [`a.put(b,ec)`] @@ -66,14 +67,16 @@ In the table below: [ This function is called to append the buffers specified by `b` into the body representation. - If `ec` is set, the error will be propagated to the caller. + The function will ensure that `!ec` is `true` if there was + no error or set to the appropriate error code if there was one. ] ][ [`a.finish(ec)`] [] [ This function is called when no more body octets are remaining. - If `ec` is set, the error will be propagated to the caller. + The function will ensure that `!ec` is `true` if there was + no error or set to the appropriate error code if there was one. ] ][ [`is_body_writer`] @@ -112,7 +115,11 @@ struct writer @param ec Set to the error, if any occurred. */ void - init(boost::optional content_length, error_code& ec); + init(boost::optional content_length, error_code& ec) + { + // The specification requires this to indicate "no error" + ec = {}; + } /** Store buffers. diff --git a/examples/doc_core_samples.hpp b/examples/doc_core_samples.hpp index e51ebb7c..8fcd8d69 100644 --- a/examples/doc_core_samples.hpp +++ b/examples/doc_core_samples.hpp @@ -132,7 +132,7 @@ detect_ssl( "SyncReadStream requirements not met"); static_assert(is_dynamic_buffer::value, "DynamicBuffer requirements not met"); - + // Loop until an error occurs or we get a definitive answer for(;;) { @@ -142,7 +142,10 @@ detect_ssl( // If we got an answer, return it if(! boost::indeterminate(result)) + { + ec = {}; // indicate no error return result; + } // The algorithm should never need more than 4 bytes BOOST_ASSERT(buffer.size() < 4); diff --git a/examples/doc_http_samples.hpp b/examples/doc_http_samples.hpp index b3aedfd1..7cfa76b1 100644 --- a/examples/doc_http_samples.hpp +++ b/examples/doc_http_samples.hpp @@ -581,6 +581,9 @@ public: using boost::asio::buffer_cast; using boost::asio::buffer_size; + // Error codes must be cleared on success + ec = {}; + // Keep a running total of how much we wrote std::size_t bytes_transferred = 0; @@ -943,6 +946,7 @@ void custom_parser:: on_request(verb method, string_view method_str, string_view path, int version, error_code& ec) { + ec = {}; } template @@ -950,6 +954,7 @@ void custom_parser:: on_response(int status, string_view reason, int version, error_code& ec) { + ec = {}; } template @@ -957,12 +962,14 @@ void custom_parser:: on_field(field f, string_view name, string_view value, error_code& ec) { + ec = {}; } template void custom_parser:: on_header(error_code& ec) { + ec = {}; } template @@ -970,12 +977,14 @@ void custom_parser:: on_body(boost::optional const& content_length, error_code& ec) { + ec = {}; } template void custom_parser:: on_data(string_view s, error_code& ec) { + ec = {}; } template @@ -983,12 +992,14 @@ void custom_parser:: on_chunk(std::uint64_t size, string_view extension, error_code& ec) { + ec = {}; } template void custom_parser:: on_complete(error_code& ec) { + ec = {}; } } // http diff --git a/examples/file_body.hpp b/examples/file_body.hpp index d8d5de8d..a560668c 100644 --- a/examples/file_body.hpp +++ b/examples/file_body.hpp @@ -181,6 +181,7 @@ init(error_code& ec) // The file was opened successfully, get the size // of the file to know how much we need to read. + ec = {}; remain_ = boost::filesystem::file_size(path_); } @@ -201,7 +202,10 @@ get(error_code& ec) -> // Check for an empty file if(amount == 0) + { + ec = {}; return boost::none; + } // Now read the next buffer auto const nread = fread(buf_, 1, amount, file_); @@ -229,6 +233,7 @@ get(error_code& ec) -> // we set this bool to `false` so we will not be called // again. // + ec = {}; return {{ const_buffers_type{buf_, nread}, // buffer to return. remain_ > 0 // `true` if there are more buffers. @@ -241,6 +246,9 @@ void file_body::reader:: finish(error_code& ec) { + // Functions which pass back errors are + // responsible for clearing the error code. + ec = {}; } // The destructor is always invoked if construction succeeds. @@ -340,6 +348,9 @@ init(boost::optional const& content_length, error_code& ec) ec = error_code{errno, system_category()}; return; } + + // Indicate success + ec = {}; } // This will get called one or more times with body buffers @@ -367,6 +378,9 @@ put(ConstBufferSequence const& buffers, error_code& ec) return; } } + + // Indicate success + ec = {}; } // Called after writing is done when there's no error. @@ -375,6 +389,7 @@ void file_body::writer:: finish(error_code& ec) { + ec = {}; } // The destructor is always invoked if construction succeeds diff --git a/extras/beast/test/fail_counter.hpp b/extras/beast/test/fail_counter.hpp index 4ad34959..29a601ef 100644 --- a/extras/beast/test/fail_counter.hpp +++ b/extras/beast/test/fail_counter.hpp @@ -149,6 +149,7 @@ public: ec = ec_; return true; } + ec = {}; return false; } }; diff --git a/extras/beast/test/pipe_stream.hpp b/extras/beast/test/pipe_stream.hpp index 0f02a49d..bcabec45 100644 --- a/extras/beast/test/pipe_stream.hpp +++ b/extras/beast/test/pipe_stream.hpp @@ -196,6 +196,7 @@ public: teardown(websocket::teardown_tag, stream&, boost::system::error_code& ec) { + ec = {}; } template @@ -367,6 +368,7 @@ read_some(MutableBufferSequence const& buffers, std::size_t bytes_transferred; if(in_.b.size() > 0) { + ec = {}; bytes_transferred = buffer_copy( buffers, in_.b.data(), read_max_); in_.b.consume(bytes_transferred); @@ -478,6 +480,7 @@ write_some( else out_.cv.notify_all(); ++nwrite; + ec = {}; return bytes_transferred; } diff --git a/extras/beast/test/string_iostream.hpp b/extras/beast/test/string_iostream.hpp index 9c441b96..83f0898e 100644 --- a/extras/beast/test/string_iostream.hpp +++ b/extras/beast/test/string_iostream.hpp @@ -72,9 +72,14 @@ public: auto const n = boost::asio::buffer_copy( buffers, buffer_prefix(read_max_, cb_)); if(n > 0) + { + ec = {}; cb_ = cb_ + n; + } else + { ec = boost::asio::error::eof; + } return n; } @@ -112,8 +117,9 @@ public: template std::size_t write_some( - ConstBufferSequence const& buffers, error_code&) + ConstBufferSequence const& buffers, error_code& ec) { + ec = {}; using boost::asio::buffer_size; using boost::asio::buffer_cast; auto const n = buffer_size(buffers); @@ -145,6 +151,7 @@ public: string_iostream& stream, boost::system::error_code& ec) { + ec = {}; } template diff --git a/extras/beast/test/string_istream.hpp b/extras/beast/test/string_istream.hpp index ff4d7421..86f1af52 100644 --- a/extras/beast/test/string_istream.hpp +++ b/extras/beast/test/string_istream.hpp @@ -69,9 +69,14 @@ public: auto const n = boost::asio::buffer_copy( buffers, cb_, read_max_); if(n > 0) + { + ec = {}; cb_ = cb_ + n; + } else + { ec = boost::asio::error::eof; + } return n; } @@ -109,8 +114,9 @@ public: template std::size_t write_some(ConstBufferSequence const& buffers, - error_code&) + error_code& ec) { + ec = {}; return boost::asio::buffer_size(buffers); } @@ -133,6 +139,7 @@ public: string_istream& stream, boost::system::error_code& ec) { + ec = {}; } template diff --git a/extras/beast/test/string_ostream.hpp b/extras/beast/test/string_ostream.hpp index 397badfd..cee4a3ef 100644 --- a/extras/beast/test/string_ostream.hpp +++ b/extras/beast/test/string_ostream.hpp @@ -91,8 +91,9 @@ public: template std::size_t write_some( - ConstBufferSequence const& buffers, error_code&) + ConstBufferSequence const& buffers, error_code& ec) { + ec = {}; using boost::asio::buffer_size; using boost::asio::buffer_cast; auto const n = @@ -125,6 +126,7 @@ public: string_ostream& stream, boost::system::error_code& ec) { + ec = {}; } template diff --git a/include/beast/core/impl/buffered_read_stream.ipp b/include/beast/core/impl/buffered_read_stream.ipp index a8c32b7f..428db15a 100644 --- a/include/beast/core/impl/buffered_read_stream.ipp +++ b/include/beast/core/impl/buffered_read_stream.ipp @@ -225,6 +225,10 @@ read_some(MutableBufferSequence const& buffers, if(ec) return 0; } + else + { + ec = {}; + } auto bytes_transferred = buffer_copy(buffers, sb_.data()); sb_.consume(bytes_transferred); diff --git a/include/beast/http/basic_parser.hpp b/include/beast/http/basic_parser.hpp index 292aa050..07ecb9e0 100644 --- a/include/beast/http/basic_parser.hpp +++ b/include/beast/http/basic_parser.hpp @@ -52,8 +52,11 @@ namespace http { Every callback must be provided by the derived class, or else a compilation error will be generated. This exemplar shows the signature and description of the callbacks required in - the derived class. If a callback sets the error code, the error - will be propagated to the caller of the parser. + the derived class. + For each callback, the function will ensure that `!ec` is `true` + if there was no error or set to the appropriate error code if + there was one. If an error is set, the value is propagated to + the caller of the parser. @tparam isRequest A `bool` indicating whether the parser will be presented with request or response message. diff --git a/include/beast/http/buffer_body.hpp b/include/beast/http/buffer_body.hpp index 9932f7c0..4de08315 100644 --- a/include/beast/http/buffer_body.hpp +++ b/include/beast/http/buffer_body.hpp @@ -110,8 +110,9 @@ struct buffer_body } void - init(error_code&) + init(error_code& ec) { + ec = {}; } boost::optional< @@ -125,22 +126,30 @@ struct buffer_body toggle_ = false; ec = error::need_buffer; } + else + { + ec = {}; + } return boost::none; } if(body_.data) { + ec = {}; toggle_ = true; return {{const_buffers_type{ body_.data, body_.size}, body_.more}}; } if(body_.more) ec = error::need_buffer; + else + ec = {}; return boost::none; } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; #endif @@ -162,8 +171,9 @@ struct buffer_body } void - init(boost::optional, error_code&) + init(boost::optional, error_code& ec) { + ec = {}; } template @@ -179,6 +189,7 @@ struct buffer_body ec = error::need_buffer; return; } + ec = {}; auto const bytes_transferred = buffer_copy(boost::asio::buffer( body_.data, body_.size), buffers); @@ -188,8 +199,9 @@ struct buffer_body } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; #endif diff --git a/include/beast/http/detail/basic_parser.hpp b/include/beast/http/detail/basic_parser.hpp index 1a475868..d78fff10 100644 --- a/include/beast/http/detail/basic_parser.hpp +++ b/include/beast/http/detail/basic_parser.hpp @@ -389,16 +389,23 @@ protected: for(;;) { if(it == last) + { + ec = {}; return nullptr; + } if(*it == '\r') { if(++it == last) + { + ec = {}; return nullptr; + } if(*it != '\n') { ec = error::bad_line_ending; return nullptr; } + ec = {}; return ++it; } // VFALCO Should we handle the legacy case @@ -418,30 +425,43 @@ protected: for(;;) { if(it == last) + { + ec = {}; return nullptr; + } if(*it == '\r') { if(++it == last) + { + ec = {}; return nullptr; + } if(*it != '\n') { ec = error::bad_line_ending; return nullptr; } if(++it == last) + { + ec = {}; return nullptr; + } if(*it != '\r') { ++it; continue; } if(++it == last) + { + ec = {}; return nullptr; + } if(*it != '\n') { ec = error::bad_line_ending; return nullptr; } + ec = {}; return ++it; } // VFALCO Should we handle the legacy case diff --git a/include/beast/http/dynamic_body.hpp b/include/beast/http/dynamic_body.hpp index 83d7050b..7397bc30 100644 --- a/include/beast/http/dynamic_body.hpp +++ b/include/beast/http/dynamic_body.hpp @@ -61,19 +61,22 @@ struct basic_dynamic_body } void - init(error_code&) + init(error_code& ec) { + ec = {}; } boost::optional> get(error_code& ec) { + ec = {}; return {{body_.data(), false}}; } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; #endif @@ -97,8 +100,9 @@ struct basic_dynamic_body void init(boost::optional< - std::uint64_t> const&, error_code&) + std::uint64_t> const&, error_code& ec) { + ec = {}; } template @@ -120,12 +124,14 @@ struct basic_dynamic_body ec = error::buffer_overflow; return; } + ec = {}; body_.commit(buffer_copy(*b, buffers)); } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; #endif diff --git a/include/beast/http/empty_body.hpp b/include/beast/http/empty_body.hpp index b4f1fe21..1a563c60 100644 --- a/include/beast/http/empty_body.hpp +++ b/include/beast/http/empty_body.hpp @@ -63,19 +63,22 @@ struct empty_body } void - init(error_code&) + init(error_code& ec) { + ec = {}; } boost::optional> get(error_code& ec) { + ec = {}; return boost::none; } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; #endif @@ -94,8 +97,9 @@ struct empty_body void init(boost::optional const&, - error_code&) + error_code& ec) { + ec = {}; } template @@ -107,8 +111,9 @@ struct empty_body } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; #endif diff --git a/include/beast/http/impl/basic_parser.ipp b/include/beast/http/impl/basic_parser.ipp index e37b824f..18809c27 100644 --- a/include/beast/http/impl/basic_parser.ipp +++ b/include/beast/http/impl/basic_parser.ipp @@ -94,7 +94,10 @@ put(ConstBufferSequence const& buffers, auto const p = buffers.begin(); auto const last = buffers.end(); if(p == last) + { + ec = {}; return 0; + } if(std::next(p) == last) { // single buffer @@ -196,7 +199,8 @@ loop: break; case state::complete: - break; + ec = {}; + goto done; } if(p < p1 && ! is_done() && eager()) { @@ -225,6 +229,7 @@ put_eof(error_code& ec) ec = error::partial_message; return; } + ec = {}; return; } impl().on_complete(ec); @@ -789,6 +794,7 @@ do_field(field f, continue; } } + ec = {}; return; } @@ -827,6 +833,7 @@ do_field(field f, return; } + ec = {}; len_ = v; f_ |= flagContentLength; return; @@ -849,6 +856,7 @@ do_field(field f, return; } + ec = {}; auto const v = token_list{value}; auto const p = std::find_if(v.begin(), v.end(), [&](typename token_list::value_type const& s) @@ -867,10 +875,12 @@ do_field(field f, // Upgrade if(f == field::upgrade) { - f_ |= flagUpgrade; ec = {}; + f_ |= flagUpgrade; return; } + + ec = {}; } } // http diff --git a/include/beast/http/impl/read.ipp b/include/beast/http/impl/read.ipp index 7aaa2f69..b0108719 100644 --- a/include/beast/http/impl/read.ipp +++ b/include/beast/http/impl/read.ipp @@ -467,7 +467,6 @@ read_some( break; if(ec != http::error::need_more) break; - ec = {}; do_read: boost::optional b; @@ -479,7 +478,7 @@ read_some( catch(std::length_error const&) { ec = error::buffer_overflow; - break; + return; } auto const bytes_transferred = stream.read_some(*b, ec); @@ -489,7 +488,6 @@ read_some( if(parser.got_some()) { // caller sees EOF on next read - ec = {}; parser.put_eof(ec); if(ec) break; @@ -570,12 +568,18 @@ read_header( static_assert(is_dynamic_buffer::value, "DynamicBuffer requirements not met"); parser.eager(false); - while(! parser.is_header_done()) + if(parser.is_header_done()) + { + ec = {}; + return; + } + do { read_some(stream, buffer, parser, ec); if(ec) return; } + while(! parser.is_header_done()); } template< @@ -643,12 +647,18 @@ read( static_assert(is_dynamic_buffer::value, "DynamicBuffer requirements not met"); parser.eager(true); - while(! parser.is_done()) + if(parser.is_done()) + { + ec = {}; + return; + } + do { read_some(stream, buffer, parser, ec); if(ec) return; } + while(! parser.is_done()); } template< diff --git a/include/beast/http/impl/serializer.ipp b/include/beast/http/impl/serializer.ipp index b0691d37..8de92b67 100644 --- a/include/beast/http/impl/serializer.ipp +++ b/include/beast/http/impl/serializer.ipp @@ -60,7 +60,8 @@ get(error_code& ec, Visit&& visit) frdinit(std::integral_constant{}); close_ = m_.has_close() || ( - m_.version < 11 && ! m_.has_content_length()); + m_.version < 11 && + ! m_.has_content_length()); if(m_.has_chunked()) goto go_init_c; s_ = do_init; diff --git a/include/beast/http/impl/write.ipp b/include/beast/http/impl/write.ipp index a71cf2ca..c87960f7 100644 --- a/include/beast/http/impl/write.ipp +++ b/include/beast/http/impl/write.ipp @@ -56,6 +56,7 @@ class write_some_op operator()(error_code& ec, ConstBufferSequence const& buffer) { + ec = {}; invoked = true; return op_.s_.async_write_some( buffer, std::move(op_)); @@ -212,6 +213,7 @@ class write_op operator()(error_code& ec, ConstBufferSequence const& buffer) { + ec = {}; invoked = true; return op_.s_.async_write_some( buffer, std::move(op_)); @@ -533,14 +535,16 @@ write_some(SyncWriteStream& stream, serializer< static_assert(is_body_reader::value, "BodyReader requirements not met"); detail::write_some_lambda f{stream}; - if(! sr.is_done()) + if(sr.is_done()) { - sr.get(ec, f); - if(ec) - return; - if(f.invoked) - sr.consume(f.bytes_transferred); + ec = {}; + return; } + sr.get(ec, f); + if(ec) + return; + if(f.invoked) + sr.consume(f.bytes_transferred); } template::value, "BodyReader requirements not met"); sr.split(true); + if(sr.is_header_done()) + { + ec = {}; + return; + } detail::write_lambda f{stream}; - while(! sr.is_header_done()) + do { sr.get(ec, f); if(ec) @@ -612,6 +621,7 @@ write_header(SyncWriteStream& stream, serializer< BOOST_ASSERT(f.invoked); sr.consume(f.bytes_transferred); } + while(! sr.is_header_done()); } template::value, "SyncWriteStream requirements not met"); sr.split(false); + if(sr.is_done()) + { + ec = {}; + return; + } detail::write_lambda f{stream}; - while(! sr.is_done()) + do { sr.get(ec, f); if(ec) @@ -677,6 +692,7 @@ write(SyncWriteStream& stream, serializer< if(f.invoked) sr.consume(f.bytes_transferred); } + while(! sr.is_done()); if(sr.need_close()) ec = error::end_of_stream; } @@ -792,9 +808,12 @@ public: template void - operator()(error_code&, + operator()(error_code& ec, ConstBufferSequence const& buffers) const { + ec = {}; + if(os_.fail()) + return; std::size_t bytes_transferred = 0; using boost::asio::buffer_cast; using boost::asio::buffer_size; diff --git a/include/beast/http/parser.hpp b/include/beast/http/parser.hpp index 13ae8368..73af94ac 100644 --- a/include/beast/http/parser.hpp +++ b/include/beast/http/parser.hpp @@ -183,8 +183,9 @@ private: void on_request(verb method, string_view method_str, - string_view target, int version, error_code&) + string_view target, int version, error_code& ec) { + ec = {}; m_.target(target); if(method != verb::unknown) m_.method(method); @@ -196,8 +197,9 @@ private: void on_response(int code, string_view reason, - int version, error_code&) + int version, error_code& ec) { + ec = {}; m_.result(code); m_.version = version; m_.reason(reason); @@ -205,14 +207,16 @@ private: void on_field(field name, string_view name_string, - string_view value, error_code&) + string_view value, error_code& ec) { + ec = {}; m_.insert(name, name_string, value); } void on_header(error_code& ec) { + ec = {}; } void @@ -233,8 +237,9 @@ private: void on_chunk(std::uint64_t, - string_view, error_code&) + string_view, error_code& ec) { + ec = {}; } void @@ -242,6 +247,8 @@ private: { if(wr_) wr_->finish(ec); + else + ec = {}; } }; diff --git a/include/beast/http/string_body.hpp b/include/beast/http/string_body.hpp index 04737091..6bb357e8 100644 --- a/include/beast/http/string_body.hpp +++ b/include/beast/http/string_body.hpp @@ -63,20 +63,23 @@ struct string_body } void - init(error_code&) + init(error_code& ec) { + ec = {}; } boost::optional> - get(error_code&) + get(error_code& ec) { + ec = {}; return {{const_buffers_type{ body_.data(), body_.size()}, false}}; } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; #endif @@ -110,6 +113,7 @@ struct string_body errc::not_enough_memory); return; } + ec = {}; body_.reserve(static_cast< std::size_t>(*content_length)); } @@ -133,13 +137,15 @@ struct string_body ec = error::buffer_overflow; return; } + ec = {}; buffer_copy(boost::asio::buffer( &body_[0] + len, n), buffers); } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; #endif diff --git a/include/beast/http/string_view_body.hpp b/include/beast/http/string_view_body.hpp index b05c2c90..06b3d69a 100644 --- a/include/beast/http/string_view_body.hpp +++ b/include/beast/http/string_view_body.hpp @@ -64,19 +64,22 @@ struct string_view_body } void - init(error_code&) + init(error_code& ec) { + ec = {}; } boost::optional> get(error_code& ec) { + ec = {}; return {{{body_.data(), body_.size()}, false}}; } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; #endif diff --git a/include/beast/websocket/detail/pmd_extension.hpp b/include/beast/websocket/detail/pmd_extension.hpp index dadf94af..1ee3cbd4 100644 --- a/include/beast/websocket/detail/pmd_extension.hpp +++ b/include/beast/websocket/detail/pmd_extension.hpp @@ -461,6 +461,7 @@ deflate( } } } + ec = {}; out = buffer( buffer_cast(out), zs.total_out); return true; diff --git a/include/beast/websocket/impl/stream.ipp b/include/beast/websocket/impl/stream.ipp index 9df74539..b6101b95 100644 --- a/include/beast/websocket/impl/stream.ipp +++ b/include/beast/websocket/impl/stream.ipp @@ -148,7 +148,7 @@ do_handshake(response_type* res_p, return; do_response(res, key, ec); if(res_p) - swap(res, *res_p); + *res_p = std::move(res); } template @@ -302,6 +302,7 @@ do_response(http::header const& res, ec = error::handshake_failed; return; } + ec = {}; detail::pmd_offer offer; pmd_read(offer, res); // VFALCO see if offer satisfies pmd_config_, diff --git a/test/http/doc_http_samples.cpp b/test/http/doc_http_samples.cpp index 10c808bd..83c33467 100644 --- a/test/http/doc_http_samples.cpp +++ b/test/http/doc_http_samples.cpp @@ -122,6 +122,7 @@ public: relay(upstream.client, downstream.server, buffer, ec, [&](header& h, error_code& ec) { + ec = {}; h.erase("Content-Length"); h.replace("Transfer-Encoding", "chunked"); }); diff --git a/test/http/doc_snippets.cpp b/test/http/doc_snippets.cpp index f3e6835c..67b15125 100644 --- a/test/http/doc_snippets.cpp +++ b/test/http/doc_snippets.cpp @@ -212,6 +212,7 @@ print_cxx14(message const& m) sr.get(ec, [&sr](error_code& ec, auto const& buffer) { + ec = {}; std::cout << buffers(buffer); sr.consume(boost::asio::buffer_size(buffer)); }); @@ -238,6 +239,7 @@ struct lambda template void operator()(error_code& ec, ConstBufferSequence const& buffer) const { + ec = {}; std::cout << buffers(buffer); sr.consume(boost::asio::buffer_size(buffer)); } @@ -278,6 +280,7 @@ split_print_cxx14(message const& m) sr.get(ec, [&sr](error_code& ec, auto const& buffer) { + ec = {}; std::cout << buffers(buffer); sr.consume(boost::asio::buffer_size(buffer)); }); @@ -291,6 +294,7 @@ split_print_cxx14(message const& m) sr.get(ec, [&sr](error_code& ec, auto const& buffer) { + ec = {}; std::cout << buffers(buffer); sr.consume(boost::asio::buffer_size(buffer)); }); diff --git a/test/http/parser_bench.cpp b/test/http/parser_bench.cpp index 6e3023cd..438eeb7f 100644 --- a/test/http/parser_bench.cpp +++ b/test/http/parser_bench.cpp @@ -166,50 +166,58 @@ public: void on_request(verb, string_view, - string_view, int, error_code&) + string_view, int, error_code& ec) { + ec = {}; } void on_response(int, string_view, - int, error_code&) + int, error_code& ec) { + ec = {}; } void on_field(field, - string_view, string_view, error_code&) + string_view, string_view, error_code& ec) { + ec = {}; } void on_header(error_code& ec) { + ec = {}; } void on_body(boost::optional const&, - error_code&) + error_code& ec) { + ec = {}; } void on_data(string_view, error_code& ec) { + ec = {}; } void on_chunk(std::uint64_t, string_view, - error_code&) + error_code& ec) { + ec = {}; } void - on_complete(error_code&) + on_complete(error_code& ec) { + ec = {}; } }; diff --git a/test/http/test_parser.hpp b/test/http/test_parser.hpp index f8df6cbd..84a0eb19 100644 --- a/test/http/test_parser.hpp +++ b/test/http/test_parser.hpp @@ -58,6 +58,8 @@ public: got_on_begin = true; if(fc_) fc_->fail(ec); + else + ec = {}; } void @@ -72,6 +74,8 @@ public: got_on_begin = true; if(fc_) fc_->fail(ec); + else + ec = {}; } void @@ -81,6 +85,8 @@ public: got_on_field = true; if(fc_) fc_->fail(ec); + else + ec = {}; } void @@ -89,6 +95,8 @@ public: got_on_header = true; if(fc_) fc_->fail(ec); + else + ec = {}; } void @@ -101,6 +109,8 @@ public: static_cast(content_length_); if(fc_) fc_->fail(ec); + else + ec = {}; } void @@ -110,6 +120,8 @@ public: body.append(s.data(), s.size()); if(fc_) fc_->fail(ec); + else + ec = {}; } void @@ -119,6 +131,8 @@ public: got_on_chunk = true; if(fc_) fc_->fail(ec); + else + ec = {}; } void @@ -127,6 +141,8 @@ public: got_on_complete = true; if(fc_) fc_->fail(ec); + else + ec = {}; } }; diff --git a/test/http/write.cpp b/test/http/write.cpp index d3d9895c..f68b5774 100644 --- a/test/http/write.cpp +++ b/test/http/write.cpp @@ -55,20 +55,23 @@ public: } void - init(error_code&) + init(error_code& ec) { + ec = {}; } boost::optional> - get(error_code&) + get(error_code& ec) { + ec = {}; return {{const_buffers_type{ body_.data(), body_.size()}, false}}; } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } }; }; @@ -107,13 +110,15 @@ public: } void - init(error_code&) + init(error_code& ec) { + ec = {}; } boost::optional> - get(error_code&) + get(error_code& ec) { + ec = {}; body_.read = true; return get( std::integral_constant{}, @@ -121,8 +126,9 @@ public: } void - finish(error_code&) + finish(error_code& ec) { + ec = {}; } private: