mirror of
https://github.com/boostorg/beast.git
synced 2025-08-02 22:34:32 +02:00
Cleanup in test::stream internals:
* avoid one instantiation of `bind_handler_front` * avoid going through the 2-arg post unnecessarily in `read_op` Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
committed by
Vinnie Falco
parent
0647c902ac
commit
e9ba521c60
@@ -29,14 +29,13 @@ class stream::read_op : public stream::read_op_base
|
|||||||
using ex2_type
|
using ex2_type
|
||||||
= net::associated_executor_t<Handler, ex1_type>;
|
= net::associated_executor_t<Handler, ex1_type>;
|
||||||
|
|
||||||
class lambda
|
struct lambda
|
||||||
{
|
{
|
||||||
Handler h_;
|
Handler h_;
|
||||||
state& s_;
|
state& s_;
|
||||||
Buffers b_;
|
Buffers b_;
|
||||||
net::executor_work_guard<ex2_type> wg2_;
|
net::executor_work_guard<ex2_type> wg2_;
|
||||||
|
|
||||||
public:
|
|
||||||
lambda(lambda&&) = default;
|
lambda(lambda&&) = default;
|
||||||
lambda(lambda const&) = default;
|
lambda(lambda const&) = default;
|
||||||
|
|
||||||
@@ -99,11 +98,10 @@ public:
|
|||||||
void
|
void
|
||||||
operator()(error_code ec) override
|
operator()(error_code ec) override
|
||||||
{
|
{
|
||||||
net::post(
|
|
||||||
wg1_.get_executor(),
|
auto alloc = net::get_associated_allocator(fn_.h_);
|
||||||
bind_handler(
|
wg1_.get_executor().post(
|
||||||
std::move(fn_),
|
beast::bind_front_handler(std::move(fn_), ec), alloc);
|
||||||
ec));
|
|
||||||
wg1_.reset();
|
wg1_.reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -162,47 +160,36 @@ struct stream::run_write_op
|
|||||||
"WriteHandler type requirements not met");
|
"WriteHandler type requirements not met");
|
||||||
|
|
||||||
++in_->nwrite;
|
++in_->nwrite;
|
||||||
|
auto const complete_op = [&](error_code ec, std::size_t n)
|
||||||
// test failure
|
|
||||||
error_code ec;
|
|
||||||
if(in_->fc && in_->fc->fail(ec))
|
|
||||||
{
|
{
|
||||||
net::post(
|
net::post(
|
||||||
in_->ioc.get_executor(),
|
in_->ioc.get_executor(),
|
||||||
beast::bind_front_handler(
|
beast::bind_front_handler(std::move(h), ec, n));
|
||||||
std::move(h),
|
};
|
||||||
ec,
|
|
||||||
std::size_t{0}));
|
// test failure
|
||||||
return;
|
error_code ec;
|
||||||
|
std::size_t n = 0;
|
||||||
|
if(in_->fc && in_->fc->fail(ec))
|
||||||
|
{
|
||||||
|
return complete_op(ec, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A request to write 0 bytes to a stream is a no-op.
|
// A request to write 0 bytes to a stream is a no-op.
|
||||||
if(buffer_size(buffers) == 0)
|
if(buffer_size(buffers) == 0)
|
||||||
{
|
{
|
||||||
net::post(
|
return complete_op(ec, n);
|
||||||
in_->ioc.get_executor(),
|
|
||||||
beast::bind_front_handler(
|
|
||||||
std::move(h),
|
|
||||||
ec, std::size_t{0}));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// connection closed
|
// connection closed
|
||||||
auto out = out_.lock();
|
auto out = out_.lock();
|
||||||
if(! out)
|
if(! out)
|
||||||
{
|
{
|
||||||
ec = net::error::connection_reset;
|
return complete_op(net::error::connection_reset, n);
|
||||||
net::post(
|
|
||||||
in_->ioc.get_executor(),
|
|
||||||
beast::bind_front_handler(
|
|
||||||
std::move(h),
|
|
||||||
ec,
|
|
||||||
std::size_t{0}));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy buffers
|
// copy buffers
|
||||||
auto n = std::min<std::size_t>(
|
n = std::min<std::size_t>(
|
||||||
buffer_size(buffers), in_->write_max);
|
buffer_size(buffers), in_->write_max);
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(out->m);
|
std::lock_guard<std::mutex> lock(out->m);
|
||||||
@@ -211,12 +198,7 @@ struct stream::run_write_op
|
|||||||
out->notify_read();
|
out->notify_read();
|
||||||
}
|
}
|
||||||
BOOST_ASSERT(! ec);
|
BOOST_ASSERT(! ec);
|
||||||
net::post(
|
complete_op(ec, n);
|
||||||
in_->ioc.get_executor(),
|
|
||||||
beast::bind_front_handler(
|
|
||||||
std::move(h),
|
|
||||||
ec,
|
|
||||||
n));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user