diff --git a/include/boost/beast/_experimental/test/impl/stream.ipp b/include/boost/beast/_experimental/test/impl/stream.ipp index 98ddea90..09a6e12c 100644 --- a/include/boost/beast/_experimental/test/impl/stream.ipp +++ b/include/boost/beast/_experimental/test/impl/stream.ipp @@ -246,7 +246,9 @@ teardown( 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/http/detail/basic_parser.ipp b/include/boost/beast/http/detail/basic_parser.ipp index 5dd13d4c..31d7cd40 100644 --- a/include/boost/beast/http/detail/basic_parser.ipp +++ b/include/boost/beast/http/detail/basic_parser.ipp @@ -140,7 +140,7 @@ find_eol( } if(*it != '\n') { - ec = error::bad_line_ending; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_line_ending); return nullptr; } ec = {}; @@ -249,7 +249,7 @@ parse_token_to_eol( { if(p >= last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return p; } if(BOOST_UNLIKELY(! is_print(*p))) @@ -264,12 +264,12 @@ found_control: { if(++p >= last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return last; } if(*p++ != '\n') { - ec = error::bad_line_ending; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_line_ending); return last; } token_last = p - 2; @@ -313,7 +313,7 @@ parse_method( { if(it + 1 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(! detail::is_token_char(*it)) @@ -321,18 +321,18 @@ parse_method( } if(it + 1 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(*it != ' ') { - ec = error::bad_method; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_method); return; } if(it == first) { // cannot be empty - ec = error::bad_method; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_method); return; } result = make_string(first, it++); @@ -350,7 +350,7 @@ parse_target( { if(it + 1 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(! is_pathchar(*it)) @@ -358,18 +358,18 @@ parse_target( } if(it + 1 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(*it != ' ') { - ec = error::bad_target; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_target); return; } if(it == first) { // cannot be empty - ec = error::bad_target; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_target); return; } result = make_string(first, it++); @@ -383,48 +383,48 @@ parse_version( { if(it + 8 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(*it++ != 'H') { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } if(*it++ != 'T') { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } if(*it++ != 'T') { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } if(*it++ != 'P') { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } if(*it++ != '/') { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } if(! is_digit(*it)) { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } result = 10 * (*it++ - '0'); if(*it++ != '.') { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } if(! is_digit(*it)) { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } result += *it++ - '0'; @@ -439,30 +439,30 @@ parse_status( // parse 3(digit) SP if(it + 4 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(! is_digit(*it)) { - ec = error::bad_status; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_status); return; } result = 100 * (*it++ - '0'); if(! is_digit(*it)) { - ec = error::bad_status; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_status); return; } result += 10 * (*it++ - '0'); if(! is_digit(*it)) { - ec = error::bad_status; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_status); return; } result += *it++ - '0'; if(*it++ != ' ') { - ec = error::bad_status; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_status); return; } } @@ -481,7 +481,7 @@ parse_reason( return; if(! p) { - ec = error::bad_reason; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_reason); return; } result = make_string(first, token_last); @@ -542,7 +542,7 @@ parse_field( p, last, ranges1, sizeof(ranges1)-1); if(! found && p >= last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } for(;;) @@ -552,20 +552,20 @@ parse_field( if(! is_token[static_cast< unsigned char>(*p)]) { - ec = error::bad_field; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_field); return; } ++p; if(p >= last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } } if(p == first) { // empty name - ec = error::bad_field; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_field); return; } name = make_string(first, p); @@ -578,7 +578,7 @@ parse_field( { if(p + 1 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(! (*p == ' ' || *p == '\t')) @@ -591,13 +591,13 @@ parse_field( return; if(! p) { - ec = error::bad_value; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_value); return; } // Look 1 char past the CRLF to handle obs-fold. if(p + 1 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } token_last = @@ -614,7 +614,7 @@ parse_field( buf.clear(); if (!buf.try_append(first, token_last)) { - ec = error::header_limit; + BOOST_BEAST_ASSIGN_EC(ec, error::header_limit); return; } @@ -626,7 +626,7 @@ parse_field( { if(p + 1 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(! (*p == ' ' || *p == '\t')) @@ -639,13 +639,13 @@ parse_field( return; if(! p) { - ec = error::bad_value; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_value); return; } // Look 1 char past the CRLF to handle obs-fold. if(p + 1 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } token_last = trim_back(token_last, first); @@ -654,7 +654,7 @@ parse_field( if (!buf.try_push_back(' ') || !buf.try_append(first, token_last)) { - ec = error::header_limit; + BOOST_BEAST_ASSIGN_EC(ec, error::header_limit); return; } } @@ -691,7 +691,7 @@ parse_chunk_extensions( loop: if(it == last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(*it != ' ' && *it != '\t' && *it != ';') @@ -704,7 +704,7 @@ loop: ++it; if(it == last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(*it != ' ' && *it != '\t') @@ -714,7 +714,7 @@ loop: // ';' if(*it != ';') { - ec = error::bad_chunk_extension; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension); return; } semi: @@ -724,7 +724,7 @@ semi: { if(it == last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(*it != ' ' && *it != '\t') diff --git a/include/boost/beast/http/impl/basic_parser.ipp b/include/boost/beast/http/impl/basic_parser.ipp index c5688156..1e3a357c 100644 --- a/include/boost/beast/http/impl/basic_parser.ipp +++ b/include/boost/beast/http/impl/basic_parser.ipp @@ -90,7 +90,7 @@ put(net::const_buffer buffer, BOOST_ASSERT(!is_done()); if (is_done()) { - ec = error::stale_parser; + BOOST_BEAST_ASSIGN_EC(ec, error::stale_parser); return 0; } auto p = static_cast(buffer.data()); @@ -104,7 +104,7 @@ loop: case state::nothing_yet: if(n == 0) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return 0; } state_ = state::start_line; @@ -123,7 +123,7 @@ loop: { if(n >= header_limit_) { - ec = error::header_limit; + BOOST_BEAST_ASSIGN_EC(ec, error::header_limit); goto done; } if(p + 3 <= p1) @@ -136,7 +136,7 @@ loop: n = static_cast(p1 - p); if(p >= p1) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); goto done; } BOOST_FALLTHROUGH; @@ -154,7 +154,7 @@ loop: { if(n >= header_limit_) { - ec = error::header_limit; + BOOST_BEAST_ASSIGN_EC(ec, error::header_limit); goto done; } if(p + 3 <= p1) @@ -239,14 +239,14 @@ put_eof(error_code& ec) if( state_ == state::start_line || state_ == state::fields) { - ec = error::partial_message; + BOOST_BEAST_ASSIGN_EC(ec, error::partial_message); return; } if(f_ & (flagContentLength | flagChunked)) { if(state_ != state::complete) { - ec = error::partial_message; + BOOST_BEAST_ASSIGN_EC(ec, error::partial_message); return; } ec = {}; @@ -272,7 +272,7 @@ maybe_need_more( n = header_limit_; if(n < skip_ + 4) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } auto const term = @@ -282,10 +282,10 @@ maybe_need_more( skip_ = n - 3; if(skip_ + 4 > header_limit_) { - ec = error::header_limit; + BOOST_BEAST_ASSIGN_EC(ec, error::header_limit); return; } - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } skip_ = 0; @@ -320,18 +320,18 @@ parse_start_line( return; if(version < 10 || version > 11) { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } if(p + 2 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(p[0] != '\r' || p[1] != '\n') { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } p += 2; @@ -368,19 +368,19 @@ parse_start_line( return; if(version < 10 || version > 11) { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } // SP if(p + 1 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(*p++ != ' ') { - ec = error::bad_version; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_version); return; } @@ -421,13 +421,15 @@ parse_fields(char const*& in, { if(p + 2 > last) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(p[0] == '\r') { if(p[1] != '\n') - ec = error::bad_line_ending; + { + BOOST_BEAST_ASSIGN_EC(ec, error::bad_line_ending); + } in = p + 2; return; } @@ -462,7 +464,7 @@ finish_header(error_code& ec, std::true_type) if(body_limit_.has_value() && len_ > body_limit_) { - ec = error::body_limit; + BOOST_BEAST_ASSIGN_EC(ec, error::body_limit); return; } if(len_ > 0) @@ -527,7 +529,7 @@ finish_header(error_code& ec, std::false_type) if(body_limit_.has_value() && len_ > body_limit_) { - ec = error::body_limit; + BOOST_BEAST_ASSIGN_EC(ec, error::body_limit); return; } } @@ -591,7 +593,7 @@ parse_body_to_eof(char const*& p, { if (n > *body_limit_) { - ec = error::body_limit; + BOOST_BEAST_ASSIGN_EC(ec, error::body_limit); return; } *body_limit_ -= n; @@ -631,7 +633,7 @@ parse_chunk_header(char const*& p0, { if(n < skip_ + 2) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } if(f_ & flagExpectCRLF) @@ -641,7 +643,7 @@ parse_chunk_header(char const*& p0, // be parsed in one call instead of two. if(! parse_crlf(p)) { - ec = error::bad_chunk; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk); return; } } @@ -650,7 +652,7 @@ parse_chunk_header(char const*& p0, return; if(! eol) { - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); skip_ = n - 1; return; } @@ -660,7 +662,7 @@ parse_chunk_header(char const*& p0, std::uint64_t size; if(! parse_hex(p, size)) { - ec = error::bad_chunk; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk); return; } if(size != 0) @@ -669,7 +671,7 @@ parse_chunk_header(char const*& p0, { if (size > *body_limit_) { - ec = error::body_limit; + BOOST_BEAST_ASSIGN_EC(ec, error::body_limit); return; } *body_limit_ -= size; @@ -680,7 +682,7 @@ parse_chunk_header(char const*& p0, return; if(p != eol -2 ) { - ec = error::bad_chunk_extension; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension); return; } auto const ext = make_string(start, p); @@ -713,7 +715,7 @@ parse_chunk_header(char const*& p0, { BOOST_ASSERT(n >= 3); skip_ = n - 3; - ec = error::need_more; + BOOST_BEAST_ASSIGN_EC(ec, error::need_more); return; } @@ -723,7 +725,7 @@ parse_chunk_header(char const*& p0, return; if(p != eol - 2) { - ec = error::bad_chunk_extension; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension); return; } auto const ext = make_string(start, p); @@ -774,7 +776,7 @@ do_field(field f, if(! validate_list(list)) { // VFALCO Should this be a field specific error? - ec = error::bad_value; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_value); return; } for(auto const& s : list) @@ -806,12 +808,12 @@ do_field(field f, { auto bad_content_length = [&ec] { - ec = error::bad_content_length; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_content_length); }; auto multiple_content_length = [&ec] { - ec = error::multiple_content_length; + BOOST_BEAST_ASSIGN_EC(ec, error::multiple_content_length); }; // conflicting field @@ -861,14 +863,14 @@ do_field(field f, if(f_ & flagChunked) { // duplicate - ec = error::bad_transfer_encoding; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_transfer_encoding); return; } if(f_ & flagContentLength) { // conflicting field - ec = error::bad_transfer_encoding; + BOOST_BEAST_ASSIGN_EC(ec, error::bad_transfer_encoding); return; } diff --git a/include/boost/beast/http/impl/file_body_win32.hpp b/include/boost/beast/http/impl/file_body_win32.hpp index 02bd5222..9066f5f1 100644 --- a/include/boost/beast/http/impl/file_body_win32.hpp +++ b/include/boost/beast/http/impl/file_body_win32.hpp @@ -471,7 +471,7 @@ public: { if(ec) { - ec = make_win32_error(ec); + BOOST_BEAST_ASSIGN_EC(ec, make_win32_error(ec)); } else if(! ec && ! header_) { @@ -573,8 +573,8 @@ write_some( 0); if(! bSuccess) { - ec = detail::make_win32_error( - boost::winapi::GetLastError()); + BOOST_BEAST_ASSIGN_EC(ec, detail::make_win32_error( + boost::winapi::GetLastError())); return 0; } w.pos_ += nNumberOfBytesToWrite; diff --git a/include/boost/beast/http/impl/write.hpp b/include/boost/beast/http/impl/write.hpp index 51f6c6a1..1739e024 100644 --- a/include/boost/beast/http/impl/write.hpp +++ b/include/boost/beast/http/impl/write.hpp @@ -238,7 +238,9 @@ public: } bytes_transferred_ += bytes_transferred; if (!ec && st_.cancelled() != net::cancellation_type::none) - ec = net::error::operation_aborted; + { + BOOST_BEAST_ASSIGN_EC(ec, net::error::operation_aborted); + } if(ec) goto upcall; if(Predicate{}(sr_)) diff --git a/include/boost/beast/zlib/detail/deflate_stream.ipp b/include/boost/beast/zlib/detail/deflate_stream.ipp index 282a1da8..53ac6c0a 100644 --- a/include/boost/beast/zlib/detail/deflate_stream.ipp +++ b/include/boost/beast/zlib/detail/deflate_stream.ipp @@ -326,7 +326,7 @@ doParams(z_params& zs, int level, Strategy strategy, error_code& ec) level = 6; if(level < 0 || level > 9) { - ec = error::stream_error; + BOOST_BEAST_ASSIGN_EC(ec, error::stream_error); return; } func = get_config(level_).func; @@ -366,12 +366,12 @@ doWrite(z_params& zs, boost::optional flush, error_code& ec) if(zs.next_out == nullptr || (status_ == FINISH_STATE && flush != Flush::finish)) { - ec = error::stream_error; + BOOST_BEAST_ASSIGN_EC(ec, error::stream_error); return; } if(zs.avail_out == 0) { - ec = error::need_buffers; + BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers); return; } @@ -406,14 +406,14 @@ doWrite(z_params& zs, boost::optional flush, error_code& ec) * flushes. For repeated and useless calls with Flush::finish, we keep * returning Z_STREAM_END instead of Z_BUF_ERROR. */ - ec = error::need_buffers; + BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers); return; } // User must not provide more input after the first FINISH: if(status_ == FINISH_STATE && zs.avail_in != 0) { - ec = error::need_buffers; + BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers); return; } @@ -493,7 +493,7 @@ doWrite(z_params& zs, boost::optional flush, error_code& ec) if(flush == Flush::finish) { - ec = error::end_of_stream; + BOOST_BEAST_ASSIGN_EC(ec, error::end_of_stream); return; } } @@ -505,7 +505,7 @@ doDictionary(Byte const* dict, uInt dictLength, error_code& ec) { if(lookahead_) { - ec = error::stream_error; + BOOST_BEAST_ASSIGN_EC(ec, error::stream_error); return; } @@ -561,7 +561,7 @@ doPrime(int bits, int value, error_code& ec) if((Byte *)(sym_buf_) < pending_out_ + ((Buf_size + 7) >> 3)) { - ec = error::need_buffers; + BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers); return; } diff --git a/include/boost/beast/zlib/detail/inflate_stream.ipp b/include/boost/beast/zlib/detail/inflate_stream.ipp index 42e033ae..b9da3683 100644 --- a/include/boost/beast/zlib/detail/inflate_stream.ipp +++ b/include/boost/beast/zlib/detail/inflate_stream.ipp @@ -113,12 +113,14 @@ doWrite(z_params& zs, Flush flush, error_code& ec) if(((! r.in.used() && ! r.out.used()) || flush == Flush::finish) && ! ec) - ec = error::need_buffers; + { + BOOST_BEAST_ASSIGN_EC(ec, error::need_buffers); + } }; auto const err = [&](error e) { - ec = e; + BOOST_BEAST_ASSIGN_EC(ec, e); mode_ = BAD; }; @@ -516,8 +518,10 @@ doWrite(z_params& zs, Flush flush, error_code& ec) BOOST_FALLTHROUGH; case DONE: - ec = error::end_of_stream; + { + BOOST_BEAST_ASSIGN_EC(ec, error::end_of_stream); return done(); + } case BAD: return done(); @@ -666,13 +670,13 @@ inflate_table( left -= count[len]; if (left < 0) { - ec = error::over_subscribed_length; + BOOST_BEAST_ASSIGN_EC(ec, error::over_subscribed_length); return; } } if (left > 0 && (type == build::codes || max != 1)) { - ec = error::incomplete_length_set; + BOOST_BEAST_ASSIGN_EC(ec, error::incomplete_length_set); return; } @@ -1037,7 +1041,7 @@ inflate_fast(ranges& r, error_code& ec) #ifdef INFLATE_STRICT if(dist > dmax_) { - ec = error::invalid_distance; + BOOST_BEAST_ASSIGN_EC(ec, error::invalid_distance); mode_ = BAD; break; } @@ -1051,7 +1055,7 @@ inflate_fast(ranges& r, error_code& ec) op = dist - op; // distance back in window if(op > w_.size()) { - ec = error::invalid_distance; + BOOST_BEAST_ASSIGN_EC(ec, error::invalid_distance); mode_ = BAD; break; } @@ -1078,7 +1082,7 @@ inflate_fast(ranges& r, error_code& ec) } else { - ec = error::invalid_distance_code; + BOOST_BEAST_ASSIGN_EC(ec, error::invalid_distance_code); mode_ = BAD; break; } @@ -1097,7 +1101,7 @@ inflate_fast(ranges& r, error_code& ec) } else { - ec = error::invalid_literal_length; + BOOST_BEAST_ASSIGN_EC(ec, error::invalid_literal_length); mode_ = BAD; break; } diff --git a/test/bench/parser/nodejs_parser.hpp b/test/bench/parser/nodejs_parser.hpp index 68afd6f5..7af0dec4 100644 --- a/test/bench/parser/nodejs_parser.hpp +++ b/test/bench/parser/nodejs_parser.hpp @@ -369,8 +369,10 @@ write(void const* data, &state_, hooks(), static_cast(data), size); if(! ec) - ec = detail::make_nodejs_error( - static_cast(state_.http_errno)); + { + BOOST_BEAST_ASSIGN_EC(ec, detail::make_nodejs_error( + static_cast(state_.http_errno))); + } if(ec) return 0; return n; @@ -384,8 +386,10 @@ write_eof(error_code& ec) ec_ = &ec; http_parser_execute(&state_, hooks(), nullptr, 0); if(! ec) - ec = detail::make_nodejs_error( - static_cast(state_.http_errno)); + { + BOOST_BEAST_ASSIGN_EC(ec, detail::make_nodejs_error( + static_cast(state_.http_errno))); + } } template