From 737a2a0aa96ff67db7cd09a11fdb2883a84d1233 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Sun, 17 Oct 2021 11:05:21 +1100 Subject: [PATCH] Don't use shared_ptr in basic_socket_streambuf implementation. --- include/boost/asio/basic_socket_streambuf.hpp | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/include/boost/asio/basic_socket_streambuf.hpp b/include/boost/asio/basic_socket_streambuf.hpp index bd9c8d8d..3da96233 100644 --- a/include/boost/asio/basic_socket_streambuf.hpp +++ b/include/boost/asio/basic_socket_streambuf.hpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -85,7 +84,28 @@ protected: { } - shared_ptr default_io_context_; +#if defined(BOOST_ASIO_HAS_MOVE) + socket_streambuf_io_context(socket_streambuf_io_context&& other) + : default_io_context_(other.default_io_context_) + { + other.default_io_context_ = 0; + } + + socket_streambuf_io_context& operator=(socket_streambuf_io_context&& other) + { + delete default_io_context_; + default_io_context_ = other.default_io_context_; + other.default_io_context_ = 0; + return *this; + } +#endif // defined(BOOST_ASIO_HAS_MOVE) + + io_context* default_io_context_; + +private: + // Disallow copying and assignment. + socket_streambuf_io_context(const socket_streambuf_io_context&); + socket_streambuf_io_context& operator=(const socket_streambuf_io_context&); }; // A separate base class is used to ensure that the dynamically allocated @@ -229,7 +249,7 @@ public: { this->close(); socket() = std::move(other.socket()); - detail::socket_streambuf_io_context::operator=(other); + detail::socket_streambuf_io_context::operator=(std::move(other)); ec_ = other.ec_; expiry_time_ = other.expiry_time_; get_buffer_.swap(other.get_buffer_);