Skip to content

Commit 99aa866

Browse files
Update MDNSResponder::addService to return a boolean (espressif#4365)
I was playing with the mDNS service and noticed the method MDNSResponder::addService could return a Boolean with the way it is implemented just like other functions in this library. This would be handy to know at a higher level weather or not the service was added correctly to the mDNS server of the ESP32.
1 parent 82670b9 commit 99aa866

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

libraries/ESPmDNS/src/ESPmDNS.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void MDNSResponder::disableWorkstation(){
130130
}
131131
}
132132

133-
void MDNSResponder::addService(char *name, char *proto, uint16_t port){
133+
bool MDNSResponder::addService(char *name, char *proto, uint16_t port){
134134
char _name[strlen(name)+2];
135135
char _proto[strlen(proto)+2];
136136
if (name[0] == '_') {
@@ -146,7 +146,9 @@ void MDNSResponder::addService(char *name, char *proto, uint16_t port){
146146

147147
if(mdns_service_add(NULL, _name, _proto, port, NULL, 0)) {
148148
log_e("Failed adding service %s.%s.\n", name, proto);
149+
return false;
149150
}
151+
return true;
150152
}
151153

152154
bool MDNSResponder::addServiceTxt(char *name, char *proto, char *key, char *value){

libraries/ESPmDNS/src/ESPmDNS.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ class MDNSResponder {
6565
setInstanceName(String(name));
6666
}
6767

68-
void addService(char *service, char *proto, uint16_t port);
69-
void addService(const char *service, const char *proto, uint16_t port){
70-
addService((char *)service, (char *)proto, port);
68+
bool addService(char *service, char *proto, uint16_t port);
69+
bool addService(const char *service, const char *proto, uint16_t port){
70+
return addService((char *)service, (char *)proto, port);
7171
}
72-
void addService(String service, String proto, uint16_t port){
73-
addService(service.c_str(), proto.c_str(), port);
72+
bool addService(String service, String proto, uint16_t port){
73+
return addService(service.c_str(), proto.c_str(), port);
7474
}
7575

7676
bool addServiceTxt(char *name, char *proto, char * key, char * value);

0 commit comments

Comments
 (0)