Skip to content

Commit 3f267bd

Browse files
LaborEtArsdevyte
authored andcommitted
LEAmDNS_Fixes_1_3 (#5689)
* LEAmDNS_Fixes_1_3 * Updated LEAmDNSResponder::begin()
1 parent a0108fe commit 3f267bd

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Diff for: libraries/ESP8266mDNS/src/LEAmDNS.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
*
2323
*/
2424

25+
#include <Schedule.h>
26+
2527
#include "LEAmDNS_Priv.h"
2628

29+
2730
namespace esp8266 {
2831

2932
/*
@@ -87,28 +90,30 @@ MDNSResponder::~MDNSResponder(void) {
8790
*/
8891
bool MDNSResponder::begin(const char* p_pcHostname) {
8992

90-
bool bResult = (0 != m_pcHostname);
93+
bool bResult = false;
9194

92-
if (0 == m_pcHostname) {
95+
if (0 == m_pUDPContext) {
9396
if (_setHostname(p_pcHostname)) {
9497

9598
m_GotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& pEvent) {
9699
(void) pEvent;
97-
_restart();
100+
// Ensure that _restart() runs in USER context
101+
schedule_function(std::bind(&MDNSResponder::_restart, this));
98102
});
99103

100104
m_DisconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& pEvent) {
101105
(void) pEvent;
102-
_restart();
106+
// Ensure that _restart() runs in USER context
107+
schedule_function(std::bind(&MDNSResponder::_restart, this));
103108
});
104109

105110
bResult = _restart();
106111
}
112+
DEBUG_EX_ERR(if (!bResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: FAILED for '%s'!\n"), (p_pcHostname ?: "-")); } );
107113
}
108114
else {
109-
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: Ignoring multiple calls (Ignored host domain: '%s')!\n"), (p_pcHostname ?: "-")););
115+
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: Ignoring multiple calls to begin (Ignored host domain: '%s')!\n"), (p_pcHostname ?: "-")););
110116
}
111-
DEBUG_EX_ERR(if (!bResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: FAILED for '%s'!\n"), (p_pcHostname ?: "-")); } );
112117
return bResult;
113118
}
114119

0 commit comments

Comments
 (0)