mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
More split definitions in test::stream
Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
committed by
Vinnie Falco
parent
c82237512a
commit
d048aa8e7e
@ -1,3 +1,9 @@
|
||||
Version 219:
|
||||
|
||||
* More split definitions in test::stream
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Version 218:
|
||||
|
||||
* detect_ssl, async_detect_ssl are public interfaces
|
||||
|
@ -54,15 +54,10 @@ class stream::read_op : public stream::read_op_base
|
||||
}
|
||||
|
||||
void
|
||||
operator()(bool cancel)
|
||||
operator()(error_code ec)
|
||||
{
|
||||
error_code ec;
|
||||
std::size_t bytes_transferred = 0;
|
||||
if(cancel)
|
||||
{
|
||||
ec = net::error::operation_aborted;
|
||||
}
|
||||
else
|
||||
if (!ec)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_.m);
|
||||
BOOST_ASSERT(! s_.op);
|
||||
@ -73,11 +68,12 @@ class stream::read_op : public stream::read_op_base
|
||||
b_, s_.b.data(), s_.read_max);
|
||||
s_.b.consume(bytes_transferred);
|
||||
}
|
||||
else
|
||||
else if (buffer_size(b_) > 0)
|
||||
{
|
||||
ec = net::error::eof;
|
||||
}
|
||||
}
|
||||
|
||||
auto alloc = net::get_associated_allocator(h_);
|
||||
wg2_.get_executor().dispatch(
|
||||
beast::bind_front_handler(std::move(h_),
|
||||
@ -101,13 +97,13 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
operator()(bool cancel) override
|
||||
operator()(error_code ec) override
|
||||
{
|
||||
net::post(
|
||||
wg1_.get_executor(),
|
||||
bind_handler(
|
||||
std::move(fn_),
|
||||
cancel));
|
||||
ec));
|
||||
wg1_.reset();
|
||||
}
|
||||
};
|
||||
@ -120,7 +116,7 @@ struct stream::run_read_op
|
||||
void
|
||||
operator()(
|
||||
ReadHandler&& h,
|
||||
std::shared_ptr<state> in_,
|
||||
stream& s,
|
||||
MutableBufferSequence const& buffers)
|
||||
{
|
||||
// If you get an error on the following line it means
|
||||
@ -132,71 +128,15 @@ struct stream::run_read_op
|
||||
void(error_code, std::size_t)>::value,
|
||||
"ReadHandler type requirements not met");
|
||||
|
||||
++in_->nread;
|
||||
|
||||
std::unique_lock<std::mutex> lock(in_->m);
|
||||
if(in_->op != nullptr)
|
||||
throw std::logic_error(
|
||||
"in_->op != nullptr");
|
||||
|
||||
// test failure
|
||||
error_code ec;
|
||||
if(in_->fc && in_->fc->fail(ec))
|
||||
{
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(h),
|
||||
ec, std::size_t{0}));
|
||||
return;
|
||||
}
|
||||
|
||||
// A request to read 0 bytes from a stream is a no-op.
|
||||
if(buffer_size(buffers) == 0)
|
||||
{
|
||||
lock.unlock();
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(h),
|
||||
ec, std::size_t{0}));
|
||||
return;
|
||||
}
|
||||
|
||||
// deliver bytes before eof
|
||||
if(buffer_size(in_->b.data()) > 0)
|
||||
{
|
||||
auto n = net::buffer_copy(
|
||||
buffers, in_->b.data(), in_->read_max);
|
||||
in_->b.consume(n);
|
||||
lock.unlock();
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(h),
|
||||
ec, n));
|
||||
return;
|
||||
}
|
||||
|
||||
// deliver error
|
||||
if(in_->code != status::ok)
|
||||
{
|
||||
lock.unlock();
|
||||
ec = net::error::eof;
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(h),
|
||||
ec, std::size_t{0}));
|
||||
return;
|
||||
}
|
||||
|
||||
// complete when bytes available or closed
|
||||
in_->op.reset(
|
||||
s.initiate_read(
|
||||
std::unique_ptr<read_op_base>{
|
||||
new read_op<
|
||||
ReadHandler,
|
||||
typename std::decay<ReadHandler>::type,
|
||||
MutableBufferSequence>(
|
||||
std::move(h), *in_, buffers));
|
||||
std::move(h),
|
||||
*s.in_,
|
||||
buffers)},
|
||||
buffer_size(buffers));
|
||||
}
|
||||
};
|
||||
|
||||
@ -362,7 +302,7 @@ async_read_some(
|
||||
void(error_code, std::size_t)>(
|
||||
run_read_op{},
|
||||
handler,
|
||||
in_,
|
||||
*this,
|
||||
buffers);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,45 @@ namespace beast {
|
||||
namespace test {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void stream::initiate_read(
|
||||
std::unique_ptr<stream::read_op_base>&& op,
|
||||
std::size_t buf_size)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(in_->m);
|
||||
|
||||
++in_->nread;
|
||||
if(in_->op != nullptr)
|
||||
throw std::logic_error(
|
||||
"in_->op != nullptr");
|
||||
|
||||
// test failure
|
||||
error_code ec;
|
||||
if(in_->fc && in_->fc->fail(ec))
|
||||
{
|
||||
lock.unlock();
|
||||
(*op)(ec);
|
||||
return;
|
||||
}
|
||||
|
||||
// A request to read 0 bytes from a stream is a no-op.
|
||||
if(buf_size == 0 || buffer_size(in_->b.data()) > 0)
|
||||
{
|
||||
lock.unlock();
|
||||
(*op)(ec);
|
||||
return;
|
||||
}
|
||||
|
||||
// deliver error
|
||||
if(in_->code != status::ok)
|
||||
{
|
||||
lock.unlock();
|
||||
(*op)(net::error::eof);
|
||||
return;
|
||||
}
|
||||
|
||||
// complete when bytes available or closed
|
||||
in_->op = std::move(op);
|
||||
}
|
||||
|
||||
stream::
|
||||
state::
|
||||
@ -38,7 +77,7 @@ state::
|
||||
{
|
||||
// cancel outstanding read
|
||||
if(op != nullptr)
|
||||
(*op)(true);
|
||||
(*op)(net::error::operation_aborted);
|
||||
}
|
||||
|
||||
void
|
||||
@ -49,7 +88,7 @@ notify_read()
|
||||
if(op)
|
||||
{
|
||||
auto op_ = std::move(op);
|
||||
op_->operator()();
|
||||
op_->operator()(error_code{});
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -58,7 +97,7 @@ notify_read()
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
stream::
|
||||
~stream()
|
||||
{
|
||||
@ -181,7 +220,7 @@ close()
|
||||
op = std::move(in_->op);
|
||||
}
|
||||
if(op != nullptr)
|
||||
(*op)(true);
|
||||
(*op)(net::error::operation_aborted);
|
||||
}
|
||||
|
||||
// disconnect
|
||||
|
@ -99,9 +99,11 @@ class stream
|
||||
struct read_op_base
|
||||
{
|
||||
virtual ~read_op_base() = default;
|
||||
virtual void operator()(bool cancel = false) = 0;
|
||||
virtual void operator()(error_code ec) = 0;
|
||||
};
|
||||
|
||||
BOOST_BEAST_DECL void initiate_read(std::unique_ptr<read_op_base>&& op, std::size_t buf_size);
|
||||
|
||||
template<class Handler, class Buffers>
|
||||
class read_op;
|
||||
|
||||
@ -138,7 +140,7 @@ class stream
|
||||
|
||||
BOOST_BEAST_DECL
|
||||
~state();
|
||||
|
||||
|
||||
BOOST_BEAST_DECL
|
||||
void
|
||||
notify_read();
|
||||
|
Reference in New Issue
Block a user