From 0b692080cd85a191fb6c0aff0aced72e32d06481 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 26 Oct 2014 08:24:55 -0700 Subject: [PATCH] Add shared_ptr to ssl_bundle: This gives the ssl_bundle shared ownership of the underlying ssl context so that ownership of the bundle may be transferred to other classes without introduce lifetime issues. --- beast/asio/ssl_bundle.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/beast/asio/ssl_bundle.h b/beast/asio/ssl_bundle.h index 7f776f0c9..41a4f1e0a 100644 --- a/beast/asio/ssl_bundle.h +++ b/beast/asio/ssl_bundle.h @@ -21,7 +21,9 @@ #define BEAST_ASIO_SSL_BUNDLE_H_INCLUDED #include +#include #include +#include #include namespace beast { @@ -33,21 +35,33 @@ namespace asio { */ struct ssl_bundle { - typedef boost::asio::ip::tcp::socket socket_type; - typedef boost::asio::ssl::stream stream_type; + using socket_type = boost::asio::ip::tcp::socket; + using stream_type = boost::asio::ssl::stream ; + using shared_context = std::shared_ptr; template - ssl_bundle (boost::asio::ssl::context& context, Args&&... args); + ssl_bundle (shared_context const& context_, Args&&... args); + // DEPRECATED + template + ssl_bundle (boost::asio::ssl::context& context_, Args&&... args); + + shared_context context; socket_type socket; stream_type stream; }; template -ssl_bundle::ssl_bundle (boost::asio::ssl::context& context, - Args&&... args) +ssl_bundle::ssl_bundle (shared_context const& context_, Args&&... args) : socket(std::forward(args)...) - , stream (socket, context) + , stream (socket, *context_) +{ +} + +template +ssl_bundle::ssl_bundle (boost::asio::ssl::context& context_, Args&&... args) + : socket(std::forward(args)...) + , stream (socket, context_) { }