Fix test::stream async_result transformation:

close #1322

async initiating functions must return init.result.get(). Returning the
result of post caused a compilation failure for custom completion tokens.

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
Damian Jarek
2018-11-25 18:51:38 +01:00
committed by Vinnie Falco
parent f8b3ae1186
commit 836042fd24
12 changed files with 65 additions and 55 deletions

View File

@@ -1,6 +1,7 @@
Version 193: Version 193:
* Update ssl_stream signatures for networking changes * Update ssl_stream signatures for networking changes
* Fix test::stream async_result transformation
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@@ -290,7 +290,7 @@ operator()(
{ {
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post(d.s.get_executor(), boost::asio::post(d.s.get_executor(),
bind_handler(std::move(*this), ec, 0)); beast::bind_handler(std::move(*this), ec, 0));
goto upcall; goto upcall;
} }
if(! d.s.detect_) if(! d.s.detect_)

View File

@@ -257,17 +257,18 @@ async_read_some(
using boost::asio::buffer_size; using boost::asio::buffer_size;
BOOST_BEAST_HANDLER_INIT( BOOST_BEAST_HANDLER_INIT(
ReadHandler, void(error_code, std::size_t)); ReadHandler, void(error_code, std::size_t));
if(in_->fc)
error_code ec;
if(in_->fc && in_->fc->fail(ec))
{ {
error_code ec; boost::asio::post(
if(in_->fc->fail(ec)) in_->ioc.get_executor(),
return boost::asio::post( beast::bind_front_handler(
in_->ioc.get_executor(), std::move(init.completion_handler),
bind_front_handler( ec,
std::move(init.completion_handler), 0));
ec,
0));
} }
else
{ {
std::unique_lock<std::mutex> lock{in_->m}; std::unique_lock<std::mutex> lock{in_->m};
BOOST_ASSERT(! in_->op); BOOST_ASSERT(! in_->op);
@@ -281,7 +282,7 @@ async_read_some(
++in_->nread; ++in_->nread;
boost::asio::post( boost::asio::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
error_code{}, error_code{},
bytes_transferred)); bytes_transferred));
@@ -297,7 +298,7 @@ async_read_some(
ec = boost::asio::error::connection_reset; ec = boost::asio::error::connection_reset;
boost::asio::post( boost::asio::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
ec, ec,
0)); 0));
@@ -378,39 +379,47 @@ async_write_some(ConstBufferSequence const& buffers,
WriteHandler, void(error_code, std::size_t)); WriteHandler, void(error_code, std::size_t));
auto out = out_.lock(); auto out = out_.lock();
if(! out) if(! out)
return boost::asio::post( {
boost::asio::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
boost::asio::error::connection_reset, boost::asio::error::connection_reset,
0)); 0));
BOOST_ASSERT(out->code == status::ok); }
if(in_->fc) else
{ {
BOOST_ASSERT(out->code == status::ok);
error_code ec; error_code ec;
if(in_->fc->fail(ec)) if(in_->fc && in_->fc->fail(ec))
return boost::asio::post( {
boost::asio::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
ec, ec,
0)); 0));
}
else
{
auto const n =
(std::min)(buffer_size(buffers), in_->write_max);
std::unique_lock<std::mutex> lock{out->m};
auto const bytes_transferred =
buffer_copy(out->b.prepare(n), buffers);
out->b.commit(bytes_transferred);
out->on_write();
lock.unlock();
++in_->nwrite;
boost::asio::post(
in_->ioc.get_executor(),
beast::bind_front_handler(
std::move(init.completion_handler),
error_code{},
bytes_transferred));
}
} }
auto const n =
(std::min)(buffer_size(buffers), in_->write_max);
std::unique_lock<std::mutex> lock{out->m};
auto const bytes_transferred =
buffer_copy(out->b.prepare(n), buffers);
out->b.commit(bytes_transferred);
out->on_write();
lock.unlock();
++in_->nwrite;
boost::asio::post(
in_->ioc.get_executor(),
bind_front_handler(
std::move(init.completion_handler),
error_code{},
bytes_transferred));
return init.result.get(); return init.result.get();
} }
@@ -447,7 +456,7 @@ TeardownHandler&& handler)
s.in_->fc->fail(ec)) s.in_->fc->fail(ec))
return boost::asio::post( return boost::asio::post(
s.get_executor(), s.get_executor(),
bind_front_handler(std::move(handler), ec)); beast::bind_front_handler(std::move(handler), ec));
s.close(); s.close();
if( s.in_->fc && if( s.in_->fc &&
s.in_->fc->fail(ec)) s.in_->fc->fail(ec))
@@ -457,7 +466,7 @@ TeardownHandler&& handler)
boost::asio::post( boost::asio::post(
s.get_executor(), s.get_executor(),
bind_front_handler(std::move(handler), ec)); beast::bind_front_handler(std::move(handler), ec));
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -513,7 +522,7 @@ class stream::read_op : public stream::read_op_base
++s.nread; ++s.nread;
boost::asio::post( boost::asio::post(
s.ioc.get_executor(), s.ioc.get_executor(),
bind_front_handler( beast::bind_front_handler(
std::move(h), std::move(h),
error_code{}, error_code{},
bytes_transferred)); bytes_transferred));
@@ -532,7 +541,7 @@ class stream::read_op : public stream::read_op_base
ec = boost::asio::error::connection_reset; ec = boost::asio::error::connection_reset;
boost::asio::post( boost::asio::post(
s.ioc.get_executor(), s.ioc.get_executor(),
bind_front_handler(std::move(h), ec, 0)); beast::bind_front_handler(std::move(h), ec, 0));
} }
} }
}; };

View File

@@ -126,7 +126,7 @@ read_some_op<MutableBufferSequence, Handler>::operator()(
step_ = 3; step_ = 3;
return boost::asio::post( return boost::asio::post(
s_.get_executor(), s_.get_executor(),
bind_front_handler(std::move(*this), ec, 0)); beast::bind_front_handler(std::move(*this), ec, 0));
case 1: case 1:
// upcall // upcall

View File

@@ -182,7 +182,7 @@ operator()(
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post( boost::asio::post(
s_.get_executor(), s_.get_executor(),
bind_front_handler(std::move(*this), beast::bind_front_handler(std::move(*this),
ec, bytes_transferred_)); ec, bytes_transferred_));
} }
h_(ec, bytes_transferred_); h_(ec, bytes_transferred_);
@@ -305,7 +305,7 @@ operator()(
{ {
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post(s_.get_executor(), boost::asio::post(s_.get_executor(),
bind_front_handler(std::move(*this), ec)); beast::bind_front_handler(std::move(*this), ec));
goto upcall; goto upcall;
} }
for(;;) for(;;)

View File

@@ -147,7 +147,7 @@ operator()()
BOOST_ASSERT(! f.invoked); BOOST_ASSERT(! f.invoked);
return boost::asio::post( return boost::asio::post(
s_.get_executor(), s_.get_executor(),
bind_front_handler(std::move(*this), ec, 0)); beast::bind_front_handler(std::move(*this), ec, 0));
} }
if(f.invoked) if(f.invoked)
{ {
@@ -160,7 +160,7 @@ operator()()
} }
return boost::asio::post( return boost::asio::post(
s_.get_executor(), s_.get_executor(),
bind_front_handler(std::move(*this), ec, 0)); beast::bind_front_handler(std::move(*this), ec, 0));
} }
template< template<

View File

@@ -269,7 +269,7 @@ operator()(error_code ec, std::size_t)
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post( boost::asio::post(
d.ws.get_executor(), d.ws.get_executor(),
bind_front_handler(std::move(*this), ec)); beast::bind_front_handler(std::move(*this), ec));
} }
else else
{ {

View File

@@ -304,7 +304,7 @@ operator()(
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post( boost::asio::post(
d.ws.get_executor(), d.ws.get_executor(),
bind_front_handler(std::move(*this), ec)); beast::bind_front_handler(std::move(*this), ec));
} }
{ {
auto wg = std::move(d.wg); auto wg = std::move(d.wg);

View File

@@ -140,7 +140,7 @@ operator()(error_code ec, std::size_t)
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post( boost::asio::post(
d.ws.get_executor(), d.ws.get_executor(),
bind_front_handler(std::move(*this), ec)); beast::bind_front_handler(std::move(*this), ec));
goto upcall; goto upcall;
} }
} }

View File

@@ -705,7 +705,7 @@ operator()(
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post( boost::asio::post(
ws_.get_executor(), ws_.get_executor(),
bind_front_handler(std::move(*this), beast::bind_front_handler(std::move(*this),
ec, bytes_written_)); ec, bytes_written_));
} }
h_(ec, bytes_written_); h_(ec, bytes_written_);
@@ -813,7 +813,7 @@ operator()(
if(ec) if(ec)
boost::asio::post( boost::asio::post(
ws_.get_executor(), ws_.get_executor(),
bind_front_handler( beast::bind_front_handler(
std::move(*this), ec, 0)); std::move(*this), ec, 0));
else else
read_some_op<typename read_some_op<typename

View File

@@ -118,7 +118,7 @@ operator()(error_code ec, std::size_t bytes_transferred)
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post( boost::asio::post(
s_.get_executor(), s_.get_executor(),
bind_front_handler(std::move(*this), ec, 0)); beast::bind_front_handler(std::move(*this), ec, 0));
goto upcall; goto upcall;
} }
for(;;) for(;;)

View File

@@ -578,7 +578,7 @@ operator()(
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post( boost::asio::post(
ws_.get_executor(), ws_.get_executor(),
bind_front_handler( beast::bind_front_handler(
std::move(*this), std::move(*this),
ec, bytes_transferred_)); ec, bytes_transferred_));
} }