From d517cf2627addc468089c6a8f4e50ab32d3c9a65 Mon Sep 17 00:00:00 2001 From: hsaturn Date: Mon, 2 Jan 2023 00:15:14 +0100 Subject: [PATCH] MqttBroker::server is now a unique_ptr --- src/TinyMqtt.cpp | 4 ++-- src/TinyMqtt.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TinyMqtt.cpp b/src/TinyMqtt.cpp index ed44ebc..9d5715b 100644 --- a/src/TinyMqtt.cpp +++ b/src/TinyMqtt.cpp @@ -17,7 +17,7 @@ int TinyMqtt::debug=2; MqttBroker::MqttBroker(uint16_t port) { - server = new TcpServer(port); + server.reset(new TcpServer(port)); #ifdef TINY_MQTT_ASYNC server->onClient(onClient, this); #endif @@ -29,7 +29,6 @@ MqttBroker::~MqttBroker() { delete clients[0]; } - delete server; } // private constructor used by broker only @@ -165,6 +164,7 @@ void MqttBroker::onClient(void* broker_ptr, TcpClient* client) void MqttBroker::loop() { #ifndef TINY_MQTT_ASYNC + if (not server) return; WiFiClient client = server->available(); if (client) diff --git a/src/TinyMqtt.h b/src/TinyMqtt.h index 9d160de..cea0eea 100644 --- a/src/TinyMqtt.h +++ b/src/TinyMqtt.h @@ -322,7 +322,7 @@ class MqttBroker MqttBroker(uint16_t port); ~MqttBroker(); - void begin() { server->begin(); } + void begin() { if (server) server->begin(); } void loop(); void connect(const std::string& host, uint16_t port=1883); @@ -361,7 +361,7 @@ class MqttBroker std::vector clients; private: - TcpServer* server = nullptr; + std::unique_ptr server; const char* auth_user = "guest"; const char* auth_password = "guest";