diff --git a/asio/include/asio/detail/impl/resolver_service_base.ipp b/asio/include/asio/detail/impl/resolver_service_base.ipp index a55c4beb..5848e839 100644 --- a/asio/include/asio/detail/impl/resolver_service_base.ipp +++ b/asio/include/asio/detail/impl/resolver_service_base.ipp @@ -98,6 +98,19 @@ void resolver_service_base::destroy( impl.reset(); } +void resolver_service_base::move_construct(implementation_type& impl, + implementation_type& other_impl) +{ + impl = ASIO_MOVE_CAST(implementation_type)(other_impl); +} + +void resolver_service_base::move_assign(implementation_type& impl, + resolver_service_base&, implementation_type& other_impl) +{ + destroy(impl); + impl = ASIO_MOVE_CAST(implementation_type)(other_impl); +} + void resolver_service_base::cancel( resolver_service_base::implementation_type& impl) { diff --git a/asio/include/asio/detail/resolver_service_base.hpp b/asio/include/asio/detail/resolver_service_base.hpp index 329c4900..229f4fed 100644 --- a/asio/include/asio/detail/resolver_service_base.hpp +++ b/asio/include/asio/detail/resolver_service_base.hpp @@ -57,6 +57,15 @@ public: // Destroy a resolver implementation. ASIO_DECL void destroy(implementation_type&); + // Move-construct a new resolver implementation. + ASIO_DECL void move_construct(implementation_type& impl, + implementation_type& other_impl); + + // Move-assign from another resolver implementation. + ASIO_DECL void move_assign(implementation_type& impl, + resolver_service_base& other_service, + implementation_type& other_impl); + // Cancel pending asynchronous operations. ASIO_DECL void cancel(implementation_type& impl); diff --git a/asio/include/asio/detail/winrt_resolver_service.hpp b/asio/include/asio/detail/winrt_resolver_service.hpp index 68a133e6..8b3cd0bc 100644 --- a/asio/include/asio/detail/winrt_resolver_service.hpp +++ b/asio/include/asio/detail/winrt_resolver_service.hpp @@ -80,6 +80,18 @@ public: { } + // Move-construct a new resolver implementation. + void move_construct(implementation_type&, + implementation_type&) + { + } + + // Move-assign from another resolver implementation. + void move_assign(implementation_type&, + winrt_resolver_service&, implementation_type&) + { + } + // Destroy a resolver implementation. void destroy(implementation_type&) { diff --git a/asio/include/asio/ip/basic_resolver.hpp b/asio/include/asio/ip/basic_resolver.hpp index 23c5ad81..ca4f8f93 100644 --- a/asio/include/asio/ip/basic_resolver.hpp +++ b/asio/include/asio/ip/basic_resolver.hpp @@ -28,6 +28,10 @@ #include "asio/ip/basic_resolver_results.hpp" #include "asio/ip/resolver_base.hpp" +#if defined(ASIO_HAS_MOVE) +# include +#endif // defined(ASIO_HAS_MOVE) + #if defined(ASIO_ENABLE_OLD_SERVICES) # include "asio/ip/resolver_service.hpp" #else // defined(ASIO_ENABLE_OLD_SERVICES) @@ -88,13 +92,49 @@ public: * This constructor creates a basic_resolver. * * @param io_context The io_context object that the resolver will use to - * dispatch handlers for any asynchronous operations performed on the timer. + * dispatch handlers for any asynchronous operations performed on the + * resolver. */ explicit basic_resolver(asio::io_context& io_context) : basic_io_object(io_context) { } +#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Move-construct a basic_resolver from another. + /** + * This constructor moves a resolver from one object to another. + * + * @param other The other basic_resolver object from which the move will + * occur. + * + * @note Following the move, the moved-from object is in the same state as if + * constructed using the @c basic_resolver(io_context&) constructor. + */ + basic_resolver(basic_resolver&& other) + : basic_io_object(std::move(other)) + { + } + + /// Move-assign a basic_resolver from another. + /** + * This assignment operator moves a resolver from one object to another. + * Cancels any outstanding asynchronous operations associated with the target + * object. + * + * @param other The other basic_resolver object from which the move will + * occur. + * + * @note Following the move, the moved-from object is in the same state as if + * constructed using the @c basic_resolver(io_context&) constructor. + */ + basic_resolver& operator=(basic_resolver&& other) + { + basic_io_object::operator=(std::move(other)); + return *this; + } +#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Destroys the resolver. /** * This function destroys the resolver, cancelling any outstanding diff --git a/asio/include/asio/ip/resolver_service.hpp b/asio/include/asio/ip/resolver_service.hpp index eb80b16c..ef1a28c3 100644 --- a/asio/include/asio/ip/resolver_service.hpp +++ b/asio/include/asio/ip/resolver_service.hpp @@ -100,6 +100,23 @@ public: service_impl_.construct(impl); } +#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Move-construct a new resolver implementation. + void move_construct(implementation_type& impl, + implementation_type& other_impl) + { + service_impl_.move_construct(impl, other_impl); + } + + /// Move-assign from another resolver implementation. + void move_assign(implementation_type& impl, + resolver_service& other_service, + implementation_type& other_impl) + { + service_impl_.move_assign(impl, other_service.service_impl_, other_impl); + } +#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Destroy a resolver implementation. void destroy(implementation_type& impl) { diff --git a/asio/src/tests/unit/ip/icmp.cpp b/asio/src/tests/unit/ip/icmp.cpp index 783d9a87..9d27fac6 100644 --- a/asio/src/tests/unit/ip/icmp.cpp +++ b/asio/src/tests/unit/ip/icmp.cpp @@ -444,6 +444,17 @@ void test() ip::icmp::resolver resolver(ioc); +#if defined(ASIO_HAS_MOVE) + ip::icmp::resolver resolver2(std::move(resolver)); +#endif // defined(ASIO_HAS_MOVE) + + // basic_resolver operators. + +#if defined(ASIO_HAS_MOVE) + resolver = ip::icmp::resolver(ioc); + resolver = std::move(resolver2); +#endif // defined(ASIO_HAS_MOVE) + // basic_io_object functions. io_context& ioc_ref = resolver.get_io_context(); diff --git a/asio/src/tests/unit/ip/tcp.cpp b/asio/src/tests/unit/ip/tcp.cpp index fde7d229..a3165df1 100644 --- a/asio/src/tests/unit/ip/tcp.cpp +++ b/asio/src/tests/unit/ip/tcp.cpp @@ -985,6 +985,17 @@ void test() ip::tcp::resolver resolver(ioc); +#if defined(ASIO_HAS_MOVE) + ip::tcp::resolver resolver2(std::move(resolver)); +#endif // defined(ASIO_HAS_MOVE) + + // basic_resolver operators. + +#if defined(ASIO_HAS_MOVE) + resolver = ip::tcp::resolver(ioc); + resolver = std::move(resolver2); +#endif // defined(ASIO_HAS_MOVE) + // basic_io_object functions. io_context& ioc_ref = resolver.get_io_context(); diff --git a/asio/src/tests/unit/ip/udp.cpp b/asio/src/tests/unit/ip/udp.cpp index 56c8b6bb..f8417d69 100644 --- a/asio/src/tests/unit/ip/udp.cpp +++ b/asio/src/tests/unit/ip/udp.cpp @@ -541,6 +541,17 @@ void test() ip::udp::resolver resolver(ioc); +#if defined(ASIO_HAS_MOVE) + ip::udp::resolver resolver2(std::move(resolver)); +#endif // defined(ASIO_HAS_MOVE) + + // basic_resolver operators. + +#if defined(ASIO_HAS_MOVE) + resolver = ip::udp::resolver(ioc); + resolver = std::move(resolver2); +#endif // defined(ASIO_HAS_MOVE) + // basic_io_object functions. io_context& ioc_ref = resolver.get_io_context();