Skip to content

Commit 2d9253e

Browse files
dok-netd-a-v
authored andcommitted
The use of bind in Ticker.h is prone to type inference failure (esp8266#6129)
* std::bind has issues with type inference, use lambdas whereever possible. * Fix indentation. * More descriptive placeholder name in lambda expression * Use formal argument names for remaining currying placeholders
1 parent 09f6b87 commit 2d9253e

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

libraries/ESP8266mDNS/src/LEAmDNS.cpp

+17-15
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ bool MDNSResponder::begin(const char* p_pcHostname) {
9797
m_GotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& pEvent) {
9898
(void) pEvent;
9999
// Ensure that _restart() runs in USER context
100-
schedule_function(std::bind(&MDNSResponder::_restart, this));
100+
schedule_function([this]() { MDNSResponder::_restart(); });
101101
});
102102

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

109109
bResult = _restart();
110110
}
@@ -137,10 +137,10 @@ bool MDNSResponder::begin(const char* p_pcHostname,
137137
*/
138138
bool MDNSResponder::close(void) {
139139

140-
m_GotIPHandler.reset(); // reset WiFi event callbacks.
141-
m_DisconnectedHandler.reset();
140+
m_GotIPHandler.reset(); // reset WiFi event callbacks.
141+
m_DisconnectedHandler.reset();
142142

143-
_announce(false, true);
143+
_announce(false, true);
144144
_resetProbeStatus(false); // Stop probing
145145

146146
_releaseServiceQueries();
@@ -159,7 +159,7 @@ bool MDNSResponder::close(void) {
159159
*/
160160

161161
bool MDNSResponder::end(void) {
162-
return close();
162+
return close();
163163
}
164164

165165
/*
@@ -832,11 +832,11 @@ uint32_t MDNSResponder::answerCount(const MDNSResponder::hMDNSServiceQuery p_hSe
832832

833833
std::vector<MDNSResponder::MDNSServiceInfo> MDNSResponder::answerInfo (const MDNSResponder::hMDNSServiceQuery p_hServiceQuery) {
834834
std::vector<MDNSResponder::MDNSServiceInfo> tempVector;
835-
for (uint32_t i=0;i<answerCount(p_hServiceQuery);i++)
835+
for (uint32_t i=0;i<answerCount(p_hServiceQuery);i++)
836836
{
837-
tempVector.emplace_back(*this,p_hServiceQuery,i);
837+
tempVector.emplace_back(*this,p_hServiceQuery,i);
838838
}
839-
return tempVector;
839+
return tempVector;
840840
}
841841

842842
/*
@@ -1053,14 +1053,14 @@ const char* MDNSResponder::answerTxts(const MDNSResponder::hMDNSServiceQuery p_h
10531053
*/
10541054
bool MDNSResponder::setHostProbeResultCallback(MDNSResponder::MDNSHostProbeFn p_fnCallback) {
10551055

1056-
m_HostProbeInformation.m_fnHostProbeResultCallback = p_fnCallback;
1056+
m_HostProbeInformation.m_fnHostProbeResultCallback = p_fnCallback;
10571057

10581058
return true;
10591059
}
10601060

10611061
bool MDNSResponder::setHostProbeResultCallback(MDNSHostProbeFn1 pfn) {
1062-
using namespace std::placeholders;
1063-
return setHostProbeResultCallback(std::bind(pfn, std::ref(*this), _1, _2));
1062+
using namespace std::placeholders;
1063+
return setHostProbeResultCallback([resp=std::ref(*this), pfn](const char* p_pcDomainName, bool p_bProbeResult) { pfn(resp, p_pcDomainName, p_bProbeResult); });
10641064
}
10651065

10661066
/*
@@ -1088,8 +1088,10 @@ bool MDNSResponder::setServiceProbeResultCallback(const MDNSResponder::hMDNSServ
10881088

10891089
bool MDNSResponder::setServiceProbeResultCallback(const MDNSResponder::hMDNSService p_hService,
10901090
MDNSResponder::MDNSServiceProbeFn1 p_fnCallback) {
1091-
using namespace std::placeholders;
1092-
return setServiceProbeResultCallback(p_hService, std::bind(p_fnCallback, std::ref(*this), _1, _2, _3));
1091+
using namespace std::placeholders;
1092+
return setServiceProbeResultCallback(p_hService, [resp=std::ref(*this), p_fnCallback](const char* p_pcServiceName, const hMDNSService p_hMDNSService, bool p_bProbeResult) {
1093+
p_fnCallback(resp, p_pcServiceName, p_hMDNSService, p_bProbeResult);
1094+
});
10931095
}
10941096

10951097

libraries/Ticker/Ticker.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Ticker
4343

4444
void attach_scheduled(float seconds, callback_function_t callback)
4545
{
46-
attach(seconds,std::bind(schedule_function, callback));
46+
attach(seconds, [callback]() { schedule_function(callback); });
4747
}
4848

4949
void attach(float seconds, callback_function_t callback)
@@ -54,7 +54,7 @@ class Ticker
5454

5555
void attach_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
5656
{
57-
attach_ms(milliseconds, std::bind(schedule_function, callback));
57+
attach_ms(milliseconds, [callback]() { schedule_function(callback); });
5858
}
5959

6060
void attach_ms(uint32_t milliseconds, callback_function_t callback)
@@ -84,7 +84,7 @@ class Ticker
8484

8585
void once_scheduled(float seconds, callback_function_t callback)
8686
{
87-
once(seconds, std::bind(schedule_function, callback));
87+
once(seconds, [callback]() { schedule_function(callback); });
8888
}
8989

9090
void once(float seconds, callback_function_t callback)
@@ -95,7 +95,7 @@ class Ticker
9595

9696
void once_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
9797
{
98-
once_ms(milliseconds, std::bind(schedule_function, callback));
98+
once_ms(milliseconds, [callback]() { schedule_function(callback); });
9999
}
100100

101101
void once_ms(uint32_t milliseconds, callback_function_t callback)

0 commit comments

Comments
 (0)