Update to Beast 1.0.0-b34:

Merge commit 'd8dea963fa5dc26b4be699ce6d4bf699a429ca92' into develop
This commit is contained in:
Vinnie Falco
2017-04-20 13:40:52 -07:00
79 changed files with 501 additions and 315 deletions

View File

@@ -55,9 +55,8 @@ public:
}
template<class WriteFunction>
boost::tribool
write(resume_context&&, error_code&,
WriteFunction&& wf) noexcept
bool
write(error_code&, WriteFunction&& wf) noexcept
{
wf(boost::asio::buffer(body_));
return true;
@@ -103,8 +102,6 @@ public:
{
std::size_t n_ = 0;
value_type const& body_;
bool suspend_ = false;
enable_yield_to yt_;
public:
template<bool isRequest, class Allocator>
@@ -120,37 +117,12 @@ public:
body_.fc_.fail(ec);
}
class do_resume
{
resume_context rc_;
public:
explicit
do_resume(resume_context&& rc)
: rc_(std::move(rc))
{
}
void
operator()()
{
rc_();
}
};
template<class WriteFunction>
boost::tribool
write(resume_context&& rc, error_code& ec,
WriteFunction&& wf) noexcept
bool
write(error_code& ec, WriteFunction&& wf) noexcept
{
if(body_.fc_.fail(ec))
return false;
suspend_ = ! suspend_;
if(suspend_)
{
yt_.get_io_service().post(do_resume{std::move(rc)});
return boost::indeterminate;
}
if(n_ >= body_.s_.size())
return true;
wf(boost::asio::buffer(body_.s_.data() + n_, 1));
@@ -639,6 +611,61 @@ public:
}
}
// Ensure completion handlers are not leaked
struct handler
{
static std::atomic<std::size_t>&
count() { static std::atomic<std::size_t> n; return n; }
handler() { ++count(); }
~handler() { --count(); }
handler(handler const&) { ++count(); }
void operator()(error_code const&) const {}
};
void
testIoService()
{
{
// Make sure handlers are not destroyed
// after calling io_service::stop
boost::asio::io_service ios;
test::string_ostream os{ios};
BEAST_EXPECT(handler::count() == 0);
message<true, string_body, fields> m;
m.method = "GET";
m.version = 11;
m.url = "/";
m.fields["Content-Length"] = "5";
m.body = "*****";
async_write(os, m, handler{});
BEAST_EXPECT(handler::count() > 0);
ios.stop();
BEAST_EXPECT(handler::count() > 0);
ios.reset();
BEAST_EXPECT(handler::count() > 0);
ios.run_one();
BEAST_EXPECT(handler::count() == 0);
}
{
// Make sure uninvoked handlers are
// destroyed when calling ~io_service
{
boost::asio::io_service ios;
test::string_ostream is{ios};
BEAST_EXPECT(handler::count() == 0);
message<true, string_body, fields> m;
m.method = "GET";
m.version = 11;
m.url = "/";
m.fields["Content-Length"] = "5";
m.body = "*****";
async_write(is, m, handler{});
BEAST_EXPECT(handler::count() > 0);
}
BEAST_EXPECT(handler::count() == 0);
}
}
void run() override
{
yield_to(&write_test::testAsyncWriteHeaders, this);
@@ -647,6 +674,7 @@ public:
testOutput();
test_std_ostream();
testOstream();
testIoService();
}
};