mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Release referenced resources in the destructor for ESP8266SSDP (#5607)
* Release referenced resources in destructor * Release referenced resources in destructor, corrected for IPV6 * Release referenced resources in destructor, per suggested changes
This commit is contained in:
parent
471dd87b5c
commit
d7094f2269
@ -127,7 +127,7 @@ struct SSDPTimer {
|
|||||||
|
|
||||||
SSDPClass::SSDPClass() :
|
SSDPClass::SSDPClass() :
|
||||||
_server(0),
|
_server(0),
|
||||||
_timer(new SSDPTimer),
|
_timer(0),
|
||||||
_port(80),
|
_port(80),
|
||||||
_ttl(SSDP_MULTICAST_TTL),
|
_ttl(SSDP_MULTICAST_TTL),
|
||||||
_respondToPort(0),
|
_respondToPort(0),
|
||||||
@ -150,10 +150,12 @@ SSDPClass::SSDPClass() :
|
|||||||
}
|
}
|
||||||
|
|
||||||
SSDPClass::~SSDPClass() {
|
SSDPClass::~SSDPClass() {
|
||||||
delete _timer;
|
end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SSDPClass::begin() {
|
bool SSDPClass::begin() {
|
||||||
|
end();
|
||||||
|
|
||||||
_pending = false;
|
_pending = false;
|
||||||
if (strcmp(_uuid,"") == 0) {
|
if (strcmp(_uuid,"") == 0) {
|
||||||
uint32_t chipId = ESP.getChipId();
|
uint32_t chipId = ESP.getChipId();
|
||||||
@ -167,10 +169,7 @@ bool SSDPClass::begin() {
|
|||||||
DEBUG_SSDP.printf("SSDP UUID: %s\n", (char *)_uuid);
|
DEBUG_SSDP.printf("SSDP UUID: %s\n", (char *)_uuid);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (_server) {
|
assert(NULL == _server);
|
||||||
_server->unref();
|
|
||||||
_server = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_server = new UdpContext;
|
_server = new UdpContext;
|
||||||
_server->ref();
|
_server->ref();
|
||||||
@ -199,6 +198,34 @@ bool SSDPClass::begin() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SSDPClass::end() {
|
||||||
|
if(!_server)
|
||||||
|
return; // object is zeroed already, nothing to do
|
||||||
|
|
||||||
|
#ifdef DEBUG_SSDP
|
||||||
|
DEBUG_SSDP.printf_P(PSTR("SSDP end ... "));
|
||||||
|
#endif
|
||||||
|
// undo all initializations done in begin(), in reverse order
|
||||||
|
_stopTimer();
|
||||||
|
|
||||||
|
_server->disconnect();
|
||||||
|
|
||||||
|
IPAddress local = WiFi.localIP();
|
||||||
|
IPAddress mcast(SSDP_MULTICAST_ADDR);
|
||||||
|
|
||||||
|
if (igmp_leavegroup(local, mcast) != ERR_OK ) {
|
||||||
|
#ifdef DEBUG_SSDP
|
||||||
|
DEBUG_SSDP.printf_P(PSTR("SSDP failed to leave igmp group\n"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
_server->unref();
|
||||||
|
_server = 0;
|
||||||
|
|
||||||
|
#ifdef DEBUG_SSDP
|
||||||
|
DEBUG_SSDP.printf_P(PSTR("ok\n"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
void SSDPClass::_send(ssdp_method_t method) {
|
void SSDPClass::_send(ssdp_method_t method) {
|
||||||
char buffer[1460];
|
char buffer[1460];
|
||||||
IPAddress ip = WiFi.localIP();
|
IPAddress ip = WiFi.localIP();
|
||||||
@ -461,6 +488,8 @@ void SSDPClass::_onTimerStatic(SSDPClass* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SSDPClass::_startTimer() {
|
void SSDPClass::_startTimer() {
|
||||||
|
_stopTimer();
|
||||||
|
_timer = new SSDPTimer();
|
||||||
ETSTimer* tm = &(_timer->timer);
|
ETSTimer* tm = &(_timer->timer);
|
||||||
const int interval = 1000;
|
const int interval = 1000;
|
||||||
os_timer_disarm(tm);
|
os_timer_disarm(tm);
|
||||||
@ -468,6 +497,16 @@ void SSDPClass::_startTimer() {
|
|||||||
os_timer_arm(tm, interval, 1 /* repeat */);
|
os_timer_arm(tm, interval, 1 /* repeat */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SSDPClass::_stopTimer() {
|
||||||
|
if(!_timer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ETSTimer* tm = &(_timer->timer);
|
||||||
|
os_timer_disarm(tm);
|
||||||
|
delete _timer;
|
||||||
|
_timer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
|
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
|
||||||
SSDPClass SSDP;
|
SSDPClass SSDP;
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,6 +61,7 @@ class SSDPClass{
|
|||||||
SSDPClass();
|
SSDPClass();
|
||||||
~SSDPClass();
|
~SSDPClass();
|
||||||
bool begin();
|
bool begin();
|
||||||
|
void end();
|
||||||
void schema(WiFiClient client);
|
void schema(WiFiClient client);
|
||||||
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
|
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
|
||||||
void setDeviceType(const char *deviceType);
|
void setDeviceType(const char *deviceType);
|
||||||
@ -95,6 +96,7 @@ class SSDPClass{
|
|||||||
void _send(ssdp_method_t method);
|
void _send(ssdp_method_t method);
|
||||||
void _update();
|
void _update();
|
||||||
void _startTimer();
|
void _startTimer();
|
||||||
|
void _stopTimer();
|
||||||
static void _onTimerStatic(SSDPClass* self);
|
static void _onTimerStatic(SSDPClass* self);
|
||||||
|
|
||||||
UdpContext* _server;
|
UdpContext* _server;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user