MqttBroker::server is now a unique_ptr
This commit is contained in:
@@ -17,7 +17,7 @@ int TinyMqtt::debug=2;
|
|||||||
|
|
||||||
MqttBroker::MqttBroker(uint16_t port)
|
MqttBroker::MqttBroker(uint16_t port)
|
||||||
{
|
{
|
||||||
server = new TcpServer(port);
|
server.reset(new TcpServer(port));
|
||||||
#ifdef TINY_MQTT_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
server->onClient(onClient, this);
|
server->onClient(onClient, this);
|
||||||
#endif
|
#endif
|
||||||
@@ -29,7 +29,6 @@ MqttBroker::~MqttBroker()
|
|||||||
{
|
{
|
||||||
delete clients[0];
|
delete clients[0];
|
||||||
}
|
}
|
||||||
delete server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private constructor used by broker only
|
// private constructor used by broker only
|
||||||
@@ -165,6 +164,7 @@ void MqttBroker::onClient(void* broker_ptr, TcpClient* client)
|
|||||||
void MqttBroker::loop()
|
void MqttBroker::loop()
|
||||||
{
|
{
|
||||||
#ifndef TINY_MQTT_ASYNC
|
#ifndef TINY_MQTT_ASYNC
|
||||||
|
if (not server) return;
|
||||||
WiFiClient client = server->available();
|
WiFiClient client = server->available();
|
||||||
|
|
||||||
if (client)
|
if (client)
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ class MqttBroker
|
|||||||
MqttBroker(uint16_t port);
|
MqttBroker(uint16_t port);
|
||||||
~MqttBroker();
|
~MqttBroker();
|
||||||
|
|
||||||
void begin() { server->begin(); }
|
void begin() { if (server) server->begin(); }
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
void connect(const std::string& host, uint16_t port=1883);
|
void connect(const std::string& host, uint16_t port=1883);
|
||||||
@@ -361,7 +361,7 @@ class MqttBroker
|
|||||||
std::vector<MqttClient*> clients;
|
std::vector<MqttClient*> clients;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TcpServer* server = nullptr;
|
std::unique_ptr<TcpServer> server;
|
||||||
|
|
||||||
const char* auth_user = "guest";
|
const char* auth_user = "guest";
|
||||||
const char* auth_password = "guest";
|
const char* auth_password = "guest";
|
||||||
|
|||||||
Reference in New Issue
Block a user