forked from boostorg/beast
Implement asio dealloc-before-invoke guarantee:
fix #215 This change guarantees that temporary memory allocated through the asio hooks by the Beast implementation is deallocated before invoking the final handler when performing composed operations. The change is accomplished by replacing std::shared_ptr with a thread-safe custom container handler_ptr to manage composed operation state. The container tracks other instances which manage the same object and resets them in a safe way before invoking the final handler. handler_ptr is provided as a public interface so that users of this library can utilize the same idiom to write their own composed operations.
This commit is contained in:
1 parent
1a26484eca
commit
01e1fa2dc9
21 files changed
+574
-322
No files matched your search
@@ -9,7 +9,9 @@
|
||||
#define BEAST_WEBSOCKET_IMPL_SSL_IPP_INCLUDED
|
||||
|
||||
#include <beast/core/async_completion.hpp>
|
||||
#include <beast/core/handler_alloc.hpp>
|
||||
#include <beast/core/handler_concepts.hpp>
|
||||
#include <beast/core/handler_ptr.hpp>
|
||||
|
||||
namespace beast {
|
||||
namespace websocket {
|
||||
@@ -38,31 +40,28 @@ class teardown_ssl_op
|
||||
|
||||
struct data
|
||||
{
|
||||
stream_type& stream;
|
||||
Handler h;
|
||||
bool cont;
|
||||
stream_type& stream;
|
||||
int state = 0;
|
||||
|
||||
template<class DeducedHandler>
|
||||
data(DeducedHandler&& h_,
|
||||
stream_type& stream_)
|
||||
: stream(stream_)
|
||||
, h(std::forward<DeducedHandler>(h_))
|
||||
, cont(boost_asio_handler_cont_helpers::
|
||||
is_continuation(h))
|
||||
data(Handler& handler, stream_type& stream_)
|
||||
: cont(boost_asio_handler_cont_helpers::
|
||||
is_continuation(handler))
|
||||
, stream(stream_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<data> d_;
|
||||
handler_ptr<data, Handler> d_;
|
||||
|
||||
public:
|
||||
template<class DeducedHandler>
|
||||
explicit
|
||||
teardown_ssl_op(
|
||||
DeducedHandler&& h, stream_type& stream)
|
||||
: d_(std::make_shared<data>(
|
||||
std::forward<DeducedHandler>(h), stream))
|
||||
: d_(make_handler_ptr<data, Handler>(
|
||||
std::forward<DeducedHandler>(
|
||||
h), stream))
|
||||
{
|
||||
(*this)(error_code{}, false);
|
||||
}
|
||||
@@ -75,7 +74,7 @@ public:
|
||||
teardown_ssl_op* op)
|
||||
{
|
||||
return boost_asio_handler_alloc_helpers::
|
||||
allocate(size, op->d_->h);
|
||||
allocate(size, op->d_.handler());
|
||||
}
|
||||
|
||||
friend
|
||||
@@ -83,7 +82,7 @@ public:
|
||||
std::size_t size, teardown_ssl_op* op)
|
||||
{
|
||||
return boost_asio_handler_alloc_helpers::
|
||||
deallocate(p, size, op->d_->h);
|
||||
deallocate(p, size, op->d_.handler());
|
||||
}
|
||||
|
||||
friend
|
||||
@@ -99,7 +98,7 @@ public:
|
||||
teardown_ssl_op* op)
|
||||
{
|
||||
return boost_asio_handler_invoke_helpers::
|
||||
invoke(f, op->d_->h);
|
||||
invoke(f, op->d_.handler());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -120,7 +119,7 @@ operator()(error_code ec, bool again)
|
||||
return;
|
||||
}
|
||||
}
|
||||
d.h(ec);
|
||||
d_.invoke(ec);
|
||||
}
|
||||
|
||||
} // detail
|
||||
|
||||
Reference in new issue
Block a user