From 4a68e3a1cef56a84607245a69e5e31892f5c222d Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 20 Jun 2017 19:03:39 -0700 Subject: [PATCH] Simplify ssl teardown composed op fix #358 --- CHANGELOG.md | 1 + include/beast/websocket/impl/ssl.ipp | 110 +-------------------------- include/beast/websocket/ssl.hpp | 1 - 3 files changed, 3 insertions(+), 109 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4347b70e..fce46c48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 64: * Simplify buffered_read_stream composed op +* Simplify ssl teardown composed op -------------------------------------------------------------------------------- diff --git a/include/beast/websocket/impl/ssl.ipp b/include/beast/websocket/impl/ssl.ipp index 791894df..88e8a5e4 100644 --- a/include/beast/websocket/impl/ssl.ipp +++ b/include/beast/websocket/impl/ssl.ipp @@ -8,18 +8,11 @@ #ifndef BEAST_WEBSOCKET_IMPL_SSL_IPP_INCLUDED #define BEAST_WEBSOCKET_IMPL_SSL_IPP_INCLUDED -#include -#include -#include -#include -#include -#include +#include namespace beast { namespace websocket { -namespace detail { - /* See @@ -34,100 +27,6 @@ Behavior of ssl::stream regarding close_ to async_shutdown will complete with eof. */ -template -class teardown_ssl_op -{ - using stream_type = - boost::asio::ssl::stream; - - struct data - { - bool cont; - stream_type& stream; - int state = 0; - - data(Handler& handler, stream_type& stream_) - : stream(stream_) - { - using boost::asio::asio_handler_is_continuation; - cont = asio_handler_is_continuation(std::addressof(handler)); - } - }; - - handler_ptr d_; - -public: - template - explicit - teardown_ssl_op( - DeducedHandler&& h, stream_type& stream) - : d_(std::forward(h), stream) - { - (*this)(error_code{}, false); - } - - void - operator()(error_code ec, bool again = true); - - friend - void* asio_handler_allocate(std::size_t size, - teardown_ssl_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate(void* p, - std::size_t size, teardown_ssl_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation( - teardown_ssl_op* op) - { - return op->d_->cont; - } - - template - friend - void asio_handler_invoke(Function&& f, - teardown_ssl_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -void -teardown_ssl_op:: -operator()(error_code ec, bool again) -{ - auto& d = *d_; - d.cont = d.cont || again; - while(!ec && d.state != 99) - { - switch(d.state) - { - case 0: - d.state = 99; - d.stream.async_shutdown(*this); - return; - } - } - d_.invoke(ec); -} - -} // detail - -//------------------------------------------------------------------------------ template void @@ -144,12 +43,7 @@ async_teardown(teardown_tag, boost::asio::ssl::stream& stream, TeardownHandler&& handler) { - static_assert(beast::is_completion_handler< - TeardownHandler, void(error_code)>::value, - "TeardownHandler requirements not met"); - detail::teardown_ssl_op::type>{std::forward( - handler), stream}; + stream.async_shutdown(std::forward(handler)); } } // websocket diff --git a/include/beast/websocket/ssl.hpp b/include/beast/websocket/ssl.hpp index d10dafdf..ca4f039c 100644 --- a/include/beast/websocket/ssl.hpp +++ b/include/beast/websocket/ssl.hpp @@ -12,7 +12,6 @@ #include #include #include -#include namespace beast { namespace websocket {