Clear the error faster

This commit is contained in:
Vinnie Falco
2017-06-19 16:57:12 -07:00
parent fc09a4cad1
commit 4d393f4c2a
28 changed files with 117 additions and 116 deletions

View File

@@ -5,6 +5,7 @@ Version 62:
* Add server-framework tests
* Doc fixes and tidy
* Tidy up namespaces in examples
* Clear the error faster
--------------------------------------------------------------------------------

View File

@@ -149,7 +149,7 @@ public:
ec = ec_;
return true;
}
ec = {};
ec.assign(0, ec.category());
return false;
}
};

View File

@@ -196,7 +196,7 @@ public:
teardown(websocket::teardown_tag,
stream&, boost::system::error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
template<class TeardownHandler>
@@ -368,7 +368,7 @@ read_some(MutableBufferSequence const& buffers,
std::size_t bytes_transferred;
if(in_.b.size() > 0)
{
ec = {};
ec.assign(0, ec.category());
bytes_transferred = buffer_copy(
buffers, in_.b.data(), read_max_);
in_.b.consume(bytes_transferred);
@@ -480,7 +480,7 @@ write_some(
else
out_.cv.notify_all();
++nwrite;
ec = {};
ec.assign(0, ec.category());
return bytes_transferred;
}

View File

@@ -73,7 +73,7 @@ public:
buffers, buffer_prefix(read_max_, cb_));
if(n > 0)
{
ec = {};
ec.assign(0, ec.category());
cb_ = cb_ + n;
}
else
@@ -119,7 +119,7 @@ public:
write_some(
ConstBufferSequence const& buffers, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
using boost::asio::buffer_size;
using boost::asio::buffer_cast;
auto const n = buffer_size(buffers);
@@ -151,7 +151,7 @@ public:
string_iostream& stream,
boost::system::error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
template<class TeardownHandler>

View File

@@ -70,7 +70,7 @@ public:
buffers, cb_, read_max_);
if(n > 0)
{
ec = {};
ec.assign(0, ec.category());
cb_ = cb_ + n;
}
else
@@ -116,7 +116,7 @@ public:
write_some(ConstBufferSequence const& buffers,
error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
return boost::asio::buffer_size(buffers);
}
@@ -139,7 +139,7 @@ public:
string_istream& stream,
boost::system::error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
template<class TeardownHandler>

View File

@@ -93,7 +93,7 @@ public:
write_some(
ConstBufferSequence const& buffers, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
using boost::asio::buffer_size;
using boost::asio::buffer_cast;
auto const n =
@@ -127,7 +127,7 @@ public:
string_ostream& stream,
boost::system::error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
template<class TeardownHandler>

View File

@@ -227,7 +227,7 @@ read_some(MutableBufferSequence const& buffers,
}
else
{
ec = {};
ec.assign(0, ec.category());
}
auto bytes_transferred =
buffer_copy(buffers, sb_.data());

View File

@@ -112,7 +112,7 @@ struct buffer_body
void
init(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
boost::optional<
@@ -128,13 +128,13 @@ struct buffer_body
}
else
{
ec = {};
ec.assign(0, ec.category());
}
return boost::none;
}
if(body_.data)
{
ec = {};
ec.assign(0, ec.category());
toggle_ = true;
return {{const_buffers_type{
body_.data, body_.size}, body_.more}};
@@ -142,14 +142,14 @@ struct buffer_body
if(body_.more)
ec = error::need_buffer;
else
ec = {};
ec.assign(0, ec.category());
return boost::none;
}
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
#endif
@@ -173,7 +173,7 @@ struct buffer_body
void
init(boost::optional<std::uint64_t>, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
template<class ConstBufferSequence>
@@ -189,7 +189,7 @@ struct buffer_body
ec = error::need_buffer;
return;
}
ec = {};
ec.assign(0, ec.category());
auto const bytes_transferred =
buffer_copy(boost::asio::buffer(
body_.data, body_.size), buffers);
@@ -201,7 +201,7 @@ struct buffer_body
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
#endif

View File

@@ -389,14 +389,14 @@ protected:
{
if(it == last)
{
ec = {};
ec.assign(0, ec.category());
return nullptr;
}
if(*it == '\r')
{
if(++it == last)
{
ec = {};
ec.assign(0, ec.category());
return nullptr;
}
if(*it != '\n')
@@ -404,7 +404,7 @@ protected:
ec = error::bad_line_ending;
return nullptr;
}
ec = {};
ec.assign(0, ec.category());
return ++it;
}
// VFALCO Should we handle the legacy case
@@ -425,14 +425,14 @@ protected:
{
if(it == last)
{
ec = {};
ec.assign(0, ec.category());
return nullptr;
}
if(*it == '\r')
{
if(++it == last)
{
ec = {};
ec.assign(0, ec.category());
return nullptr;
}
if(*it != '\n')
@@ -442,7 +442,7 @@ protected:
}
if(++it == last)
{
ec = {};
ec.assign(0, ec.category());
return nullptr;
}
if(*it != '\r')
@@ -452,7 +452,7 @@ protected:
}
if(++it == last)
{
ec = {};
ec.assign(0, ec.category());
return nullptr;
}
if(*it != '\n')
@@ -460,7 +460,7 @@ protected:
ec = error::bad_line_ending;
return nullptr;
}
ec = {};
ec.assign(0, ec.category());
return ++it;
}
// VFALCO Should we handle the legacy case

View File

@@ -61,20 +61,20 @@ struct basic_dynamic_body
void
init(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
boost::optional<std::pair<const_buffers_type, bool>>
get(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
return {{body_.data(), false}};
}
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
#endif
@@ -100,7 +100,7 @@ struct basic_dynamic_body
init(boost::optional<
std::uint64_t> const&, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
template<class ConstBufferSequence>
@@ -122,14 +122,14 @@ struct basic_dynamic_body
ec = error::buffer_overflow;
return;
}
ec = {};
ec.assign(0, ec.category());
body_.commit(buffer_copy(*b, buffers));
}
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
#endif

View File

@@ -64,20 +64,20 @@ struct empty_body
void
init(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
boost::optional<std::pair<const_buffers_type, bool>>
get(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
return boost::none;
}
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
#endif
@@ -98,7 +98,7 @@ struct empty_body
init(boost::optional<std::uint64_t> const&,
error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
template<class ConstBufferSequence>
@@ -112,7 +112,7 @@ struct empty_body
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
#endif

View File

@@ -94,7 +94,7 @@ put(ConstBufferSequence const& buffers,
auto const last = buffers.end();
if(p == last)
{
ec = {};
ec.assign(0, ec.category());
return 0;
}
if(std::next(p) == last)
@@ -198,7 +198,7 @@ loop:
break;
case state::complete:
ec = {};
ec.assign(0, ec.category());
goto done;
}
if(p < p1 && ! is_done() && eager())
@@ -228,7 +228,7 @@ put_eof(error_code& ec)
ec = error::partial_message;
return;
}
ec = {};
ec.assign(0, ec.category());
return;
}
impl().on_complete(ec);
@@ -793,7 +793,7 @@ do_field(field f,
continue;
}
}
ec = {};
ec.assign(0, ec.category());
return;
}
@@ -832,7 +832,7 @@ do_field(field f,
return;
}
ec = {};
ec.assign(0, ec.category());
len_ = v;
f_ |= flagContentLength;
return;
@@ -855,7 +855,7 @@ do_field(field f,
return;
}
ec = {};
ec.assign(0, ec.category());
auto const v = token_list{value};
auto const p = std::find_if(v.begin(), v.end(),
[&](typename token_list::value_type const& s)
@@ -874,12 +874,12 @@ do_field(field f,
// Upgrade
if(f == field::upgrade)
{
ec = {};
ec.assign(0, ec.category());
f_ |= flagUpgrade;
return;
}
ec = {};
ec.assign(0, ec.category());
}
} // http

View File

@@ -121,7 +121,7 @@ operator()(error_code ec, std::size_t bytes_transferred)
if(p_.got_some())
{
// caller sees EOF on next read
ec = {};
ec.assign(0, ec.category());
p_.put_eof(ec);
if(ec)
goto upcall;
@@ -139,7 +139,7 @@ operator()(error_code ec, std::size_t bytes_transferred)
b_.consume(p_.put(b_.data(), ec));
if(! ec || ec != http::error::need_more)
goto do_upcall;
ec = {};
ec.assign(0, ec.category());
do_read:
try
@@ -570,7 +570,7 @@ read_header(
parser.eager(false);
if(parser.is_header_done())
{
ec = {};
ec.assign(0, ec.category());
return;
}
do
@@ -649,7 +649,7 @@ read(
parser.eager(true);
if(parser.is_done())
{
ec = {};
ec.assign(0, ec.category());
return;
}
do

View File

@@ -56,7 +56,7 @@ class write_some_op
operator()(error_code& ec,
ConstBufferSequence const& buffer)
{
ec = {};
ec.assign(0, ec.category());
invoked = true;
return op_.s_.async_write_some(
buffer, std::move(op_));
@@ -213,7 +213,7 @@ class write_op
operator()(error_code& ec,
ConstBufferSequence const& buffer)
{
ec = {};
ec.assign(0, ec.category());
invoked = true;
return op_.s_.async_write_some(
buffer, std::move(op_));
@@ -537,7 +537,7 @@ write_some(SyncWriteStream& stream, serializer<
detail::write_some_lambda<SyncWriteStream> f{stream};
if(sr.is_done())
{
ec = {};
ec.assign(0, ec.category());
return;
}
sr.get(ec, f);
@@ -609,7 +609,7 @@ write_header(SyncWriteStream& stream, serializer<
sr.split(true);
if(sr.is_header_done())
{
ec = {};
ec.assign(0, ec.category());
return;
}
detail::write_lambda<SyncWriteStream> f{stream};
@@ -680,7 +680,7 @@ write(SyncWriteStream& stream, serializer<
sr.split(false);
if(sr.is_done())
{
ec = {};
ec.assign(0, ec.category());
return;
}
detail::write_lambda<SyncWriteStream> f{stream};
@@ -808,7 +808,7 @@ public:
operator()(error_code& ec,
ConstBufferSequence const& buffers) const
{
ec = {};
ec.assign(0, ec.category());
if(os_.fail())
return;
std::size_t bytes_transferred = 0;
@@ -868,7 +868,7 @@ operator<<(std::ostream& os,
if(os.fail())
break;
if(ec == error::end_of_stream)
ec = {};
ec.assign(0, ec.category());
if(ec)
{
os.setstate(std::ios::failbit);

View File

@@ -185,7 +185,7 @@ private:
on_request(verb method, string_view method_str,
string_view target, int version, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
m_.target(target);
if(method != verb::unknown)
m_.method(method);
@@ -199,7 +199,7 @@ private:
string_view reason,
int version, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
m_.result(code);
m_.version = version;
m_.reason(reason);
@@ -209,14 +209,14 @@ private:
on_field(field name, string_view name_string,
string_view value, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
m_.insert(name, name_string, value);
}
void
on_header(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
void
@@ -239,7 +239,7 @@ private:
on_chunk(std::uint64_t,
string_view, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
void
@@ -248,7 +248,7 @@ private:
if(wr_)
wr_->finish(ec);
else
ec = {};
ec.assign(0, ec.category());
}
};

View File

@@ -63,13 +63,13 @@ struct string_body
void
init(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
boost::optional<std::pair<const_buffers_type, bool>>
get(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
return {{const_buffers_type{
body_.data(), body_.size()}, false}};
}
@@ -77,7 +77,7 @@ struct string_body
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
#endif
@@ -111,7 +111,7 @@ struct string_body
errc::not_enough_memory);
return;
}
ec = {};
ec.assign(0, ec.category());
body_.reserve(static_cast<
std::size_t>(*content_length));
}
@@ -135,7 +135,7 @@ struct string_body
ec = error::buffer_overflow;
return;
}
ec = {};
ec.assign(0, ec.category());
buffer_copy(boost::asio::buffer(
&body_[0] + len, n), buffers);
}
@@ -143,7 +143,7 @@ struct string_body
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
#endif

View File

@@ -64,20 +64,20 @@ struct string_view_body
void
init(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
boost::optional<std::pair<const_buffers_type, bool>>
get(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
return {{{body_.data(), body_.size()}, false}};
}
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
#endif

View File

@@ -378,7 +378,7 @@ inflate(
if( ec == zlib::error::need_buffers ||
ec == zlib::error::end_of_stream)
{
ec = {};
ec.assign(0, ec.category());
break;
}
if(ec)
@@ -420,7 +420,7 @@ deflate(
return false;
BOOST_ASSERT(zs.avail_out == 0);
BOOST_ASSERT(zs.total_out == buffer_size(out));
ec = {};
ec.assign(0, ec.category());
break;
}
if(zs.avail_out == 0)
@@ -444,7 +444,7 @@ deflate(
zo.write(zs, zlib::Flush::block, ec);
BOOST_ASSERT(! ec || ec == zlib::error::need_buffers);
if(ec == zlib::error::need_buffers)
ec = {};
ec.assign(0, ec.category());
if(ec)
return false;
if(zs.avail_out >= 6)
@@ -459,7 +459,7 @@ deflate(
}
}
}
ec = {};
ec.assign(0, ec.category());
out = buffer(
buffer_cast<void*>(out), zs.total_out);
return true;

View File

@@ -178,7 +178,7 @@ operator()(error_code ec,
{
// Rationale:
// http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error
ec = {};
ec.assign(0, ec.category());
}
if(! ec)
{
@@ -960,7 +960,7 @@ do_close:
{
// Rationale:
// http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error
ec = {};
ec.assign(0, ec.category());
}
failed_ = ec != 0;
if(failed_)
@@ -975,7 +975,7 @@ do_close:
if(ec == boost::asio::error::eof)
{
// (See above)
ec = {};
ec.assign(0, ec.category());
}
}
if(! ec)

View File

@@ -302,7 +302,7 @@ do_response(http::header<false> const& res,
ec = error::handshake_failed;
return;
}
ec = {};
ec.assign(0, ec.category());
detail::pmd_offer offer;
pmd_read(offer, res);
// VFALCO see if offer satisfies pmd_config_,

View File

@@ -997,7 +997,7 @@ doParams(z_params& zs, int level, Strategy strategy, error_code& ec)
// Flush the last buffer:
doWrite(zs, Flush::block, ec);
if(ec == error::need_buffers && pending_ == 0)
ec = {};
ec.assign(0, ec.category());
}
if(level_ != level)
{

View File

@@ -225,7 +225,7 @@ public:
error_code ec;
p.put(buffer(s.data(), i), ec);
BEAST_EXPECTS(ec == error::need_more, ec.message());
ec = {};
ec.assign(0, ec.category());
p.put(boost::asio::buffer(s.data(), s.size()), ec);
BEAST_EXPECTS(! ec, ec.message());
BEAST_EXPECT(p.is_done());
@@ -247,7 +247,7 @@ public:
error_code ec;
p.put(b1, ec);
BEAST_EXPECTS(ec == error::need_more, ec.message());
ec = {};
ec.assign(0, ec.category());
p.put(buffer_cat(b1, b2), ec);
BEAST_EXPECTS(! ec, ec.message());
p.put_eof(ec);

View File

@@ -213,7 +213,7 @@ print_cxx14(message<isRequest, Body, Fields> const& m)
sr.get(ec,
[&sr](error_code& ec, auto const& buffer)
{
ec = {};
ec.assign(0, ec.category());
std::cout << buffers(buffer);
sr.consume(boost::asio::buffer_size(buffer));
});
@@ -240,7 +240,7 @@ struct lambda
template<class ConstBufferSequence>
void operator()(error_code& ec, ConstBufferSequence const& buffer) const
{
ec = {};
ec.assign(0, ec.category());
std::cout << buffers(buffer);
sr.consume(boost::asio::buffer_size(buffer));
}
@@ -281,7 +281,7 @@ split_print_cxx14(message<isRequest, Body, Fields> const& m)
sr.get(ec,
[&sr](error_code& ec, auto const& buffer)
{
ec = {};
ec.assign(0, ec.category());
std::cout << buffers(buffer);
sr.consume(boost::asio::buffer_size(buffer));
});
@@ -295,7 +295,7 @@ split_print_cxx14(message<isRequest, Body, Fields> const& m)
sr.get(ec,
[&sr](error_code& ec, auto const& buffer)
{
ec = {};
ec.assign(0, ec.category());
std::cout << buffers(buffer);
sr.consume(boost::asio::buffer_size(buffer));
});

View File

@@ -95,7 +95,7 @@ public:
p.put(buffer(s.data(), n), ec);
s.remove_prefix(used);
if(ec == error::need_more)
ec = {};
ec.assign(0, ec.category());
if(! BEAST_EXPECTS(! ec, ec.message()))
continue;
BEAST_EXPECT(! p.is_done());
@@ -256,7 +256,7 @@ public:
used = p.put(b.data(), ec);
b.consume(used);
BEAST_EXPECT(ec == error::need_more);
ec = {};
ec.assign(0, ec.category());
BEAST_EXPECT(! p.is_done());
ostream(b) <<
"\r\n"; // final crlf to end message
@@ -300,7 +300,7 @@ public:
used = p.put(b.data(), ec);
BEAST_EXPECTS(ec == error::need_more, ec.message());
b.consume(used);
ec = {};
ec.assign(0, ec.category());
ostream(b) <<
"User-Agent: test\r\n"
"\r\n";
@@ -321,7 +321,7 @@ public:
BEAST_EXPECT(ec == error::need_more);
BEAST_EXPECT(! p.got_some());
BEAST_EXPECT(used == 0);
ec = {};
ec.assign(0, ec.category());
used = p.put(buf("G"), ec);
BEAST_EXPECT(ec == error::need_more);
BEAST_EXPECT(p.got_some());

View File

@@ -168,7 +168,7 @@ public:
on_request(verb, string_view,
string_view, int, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
void
@@ -176,34 +176,34 @@ public:
string_view,
int, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
void
on_field(field,
string_view, string_view, error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
void
on_header(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
void
on_body(boost::optional<std::uint64_t> const&,
error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
void
on_data(string_view,
error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
void
@@ -211,13 +211,13 @@ public:
string_view,
error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
void
on_complete(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};

View File

@@ -59,7 +59,7 @@ public:
if(fc_)
fc_->fail(ec);
else
ec = {};
ec.assign(0, ec.category());
}
void
@@ -75,7 +75,7 @@ public:
if(fc_)
fc_->fail(ec);
else
ec = {};
ec.assign(0, ec.category());
}
void
@@ -86,7 +86,7 @@ public:
if(fc_)
fc_->fail(ec);
else
ec = {};
ec.assign(0, ec.category());
}
void
@@ -96,7 +96,7 @@ public:
if(fc_)
fc_->fail(ec);
else
ec = {};
ec.assign(0, ec.category());
}
void
@@ -110,7 +110,7 @@ public:
if(fc_)
fc_->fail(ec);
else
ec = {};
ec.assign(0, ec.category());
}
void
@@ -121,7 +121,7 @@ public:
if(fc_)
fc_->fail(ec);
else
ec = {};
ec.assign(0, ec.category());
}
void
@@ -132,7 +132,7 @@ public:
if(fc_)
fc_->fail(ec);
else
ec = {};
ec.assign(0, ec.category());
}
void
@@ -142,7 +142,7 @@ public:
if(fc_)
fc_->fail(ec);
else
ec = {};
ec.assign(0, ec.category());
}
};

View File

@@ -57,13 +57,13 @@ public:
void
init(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
boost::optional<std::pair<const_buffers_type, bool>>
get(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
return {{const_buffers_type{
body_.data(), body_.size()}, false}};
}
@@ -71,7 +71,7 @@ public:
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
};
};
@@ -112,13 +112,13 @@ public:
void
init(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
boost::optional<std::pair<const_buffers_type, bool>>
get(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
body_.read = true;
return get(
std::integral_constant<bool, isSplit>{},
@@ -128,7 +128,7 @@ public:
void
finish(error_code& ec)
{
ec = {};
ec.assign(0, ec.category());
}
private:

View File

@@ -224,7 +224,7 @@ public:
con.shutdown(ec);
// VFALCO No idea why we get eof in the normal case
if(ec == boost::asio::error::eof)
ec = {};
ec.assign(0, ec.category());
if(! BEAST_EXPECTS(! ec, ec.message()))
return;
}