Tidy up ssl_stream special members

fix #916
This commit is contained in:
Vinnie Falco
2017-12-01 09:07:50 -08:00
parent 13b9d1bd92
commit c01224ddc4
2 changed files with 6 additions and 17 deletions

View File

@ -1,6 +1,7 @@
Version 149:
* built-in r-value return values can't be assigned
* Tidy up ssl_stream special members
--------------------------------------------------------------------------------

View File

@ -35,11 +35,6 @@ template<class NextLayer>
class ssl_stream
: public boost::asio::ssl::stream_base
{
// only works for boost::asio::ip::tcp::socket
// for now because of the move limitations
static_assert(std::is_same<NextLayer, boost::asio::ip::tcp::socket>::value,
"NextLayer requirements not met");
using stream_type = boost::asio::ssl::stream<NextLayer>;
std::unique_ptr<stream_type> p_;
@ -61,32 +56,25 @@ public:
/// The type of the executor associated with the object.
using executor_type = typename stream_type::executor_type;
template<class Arg>
ssl_stream(
boost::asio::ip::tcp::socket socket,
Arg&& arg,
boost::asio::ssl::context& ctx)
: p_(new stream_type{
socket.get_executor().context(), ctx})
std::forward<Arg>(arg), ctx})
, ctx_(&ctx)
{
p_->next_layer() = std::move(socket);
}
ssl_stream(ssl_stream&& other)
: p_(new stream_type(
other.get_executor().context(), *other.ctx_))
: p_(std::move(other.p_))
, ctx_(other.ctx_)
{
using std::swap;
swap(p_, other.p_);
}
ssl_stream& operator=(ssl_stream&& other)
{
std::unique_ptr<stream_type> p(new stream_type{
other.get_executor().context(), other.ctx_});
using std::swap;
swap(p_, p);
swap(p_, other.p_);
p_ = std::move(other.p_);
ctx_ = other.ctx_;
return *this;
}