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 * Fix utf8 check split code point at buffer end
* Refactor stream operations and tests plus coverage * Refactor stream operations and tests plus coverage
* Suspended ops special members
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

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