diff --git a/include/async_mqtt5/mqtt_client.hpp b/include/async_mqtt5/mqtt_client.hpp index 6f39b83..1c926b4 100644 --- a/include/async_mqtt5/mqtt_client.hpp +++ b/include/async_mqtt5/mqtt_client.hpp @@ -85,8 +85,19 @@ public: mqtt_client(context.get_executor(), cnf, std::move(tls_context)) {} - /// Copy constructor. - mqtt_client(const mqtt_client& other) = delete; + /// Move-construct an mqtt_client from another. + /** Moved-from client can only be destructed. */ + mqtt_client(mqtt_client&& other) noexcept = default; + + /// Move-assign an mqtt_client from another. + /** Cancels this client first. + * Moved-from client can only be destructed. + */ + mqtt_client& operator=(mqtt_client&& other) noexcept { + cancel(); + _svc_ptr = std::move(other._svc_ptr); + return *this; + } /** * \brief Destructor. @@ -94,7 +105,7 @@ public: * \details Automatically calls \ref mqtt_client::cancel. */ ~mqtt_client() { - cancel(); + if (_svc_ptr) cancel(); } /**