Suspended ops special members

This commit is contained in:
Vinnie Falco
2017-08-31 17:10:34 -07:00
parent 51a5a36118
commit 647b3d68e1
2 changed files with 11 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ WebSocket:
* Fix utf8 check split code point at buffer end
* Refactor stream operations and tests plus coverage
* Suspended ops special members
--------------------------------------------------------------------------------

View File

@@ -32,9 +32,9 @@ class pausation
struct base
{
base() = default;
base(base &&) = default;
base(base &&) = delete;
base(base const&) = delete;
virtual ~base() = default;
virtual base* move(void* p) = 0;
virtual void operator()() = 0;
};
@@ -52,12 +52,6 @@ class pausation
{
}
base*
move(void* p) override
{
return ::new(p) holder(std::move(*this));
}
void
operator()() override
{
@@ -97,10 +91,10 @@ class pausation
using boost::asio::asio_handler_deallocate;
if(op_)
{
auto h = std::move(op_->handler());
Op op(std::move(*op_));
op_->~Op();
asio_handler_deallocate(op_,
sizeof(*op_), std::addressof(h));
sizeof(*op_), std::addressof(op.handler()));
}
}
@@ -146,36 +140,26 @@ class pausation
alignas(holder<exemplar>) buf_type buf_;
public:
pausation() = default;
pausation(pausation const&) = delete;
pausation& operator=(pausation const&) = delete;
~pausation()
{
if(base_)
base_->~base();
}
pausation() = default;
pausation(pausation&& other)
{
if(other.base_)
{
base_ = other.base_->move(buf_);
other.base_ = nullptr;
}
BOOST_ASSERT(! other.base_);
}
pausation&
operator=(pausation&& other)
{
// Engaged pausations must be invoked before
// assignment otherwise the io_service
// completion invariants are broken.
BOOST_ASSERT(! base_);
if(other.base_)
{
base_ = other.base_->move(buf_);
other.base_ = nullptr;
}
BOOST_ASSERT(! other.base_);
return *this;
}