Add shared_ptr<boost::asio::ssl::context> 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.
This commit is contained in:
Vinnie Falco
2014-10-26 08:24:55 -07:00
parent eaa021c2e2
commit 0b692080cd

View File

@@ -21,7 +21,9 @@
#define BEAST_ASIO_SSL_BUNDLE_H_INCLUDED
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <memory>
#include <utility>
namespace beast {
@@ -33,21 +35,33 @@ namespace asio {
*/
struct ssl_bundle
{
typedef boost::asio::ip::tcp::socket socket_type;
typedef boost::asio::ssl::stream <socket_type&> stream_type;
using socket_type = boost::asio::ip::tcp::socket;
using stream_type = boost::asio::ssl::stream <socket_type&>;
using shared_context = std::shared_ptr<boost::asio::ssl::context>;
template <class... Args>
ssl_bundle (boost::asio::ssl::context& context, Args&&... args);
ssl_bundle (shared_context const& context_, Args&&... args);
// DEPRECATED
template <class... Args>
ssl_bundle (boost::asio::ssl::context& context_, Args&&... args);
shared_context context;
socket_type socket;
stream_type stream;
};
template <class... Args>
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>(args)...)
, stream (socket, context)
, stream (socket, *context_)
{
}
template <class... Args>
ssl_bundle::ssl_bundle (boost::asio::ssl::context& context_, Args&&... args)
: socket(std::forward<Args>(args)...)
, stream (socket, context_)
{
}