Merge branch 'bugfix/mdns_service_limit' into 'master'

fix(mdns): add the maximum number of services

See merge request idf/esp-idf!2559
This commit is contained in:
Ivan Grokhotkov 2018-06-21 20:32:06 +08:00
commit 4b0087a387
3 changed files with 36 additions and 0 deletions

13
components/mdns/Kconfig Normal file
View File

@ -0,0 +1,13 @@
menu "mDNS"
config MDNS_MAX_SERVICES
int "Max number of services"
range 1 64
default 10
help
Services take up a certain amount of memory, and allowing fewer
services to be open at the same time conserves memory. Specify
the maximum amount of services here. The valid value is from 1
to 64.
endmenu

View File

@ -96,6 +96,21 @@ static mdns_srv_item_t * _mdns_get_service_item(const char * service, const char
return NULL;
}
static bool _mdns_can_add_more_services(void)
{
mdns_srv_item_t * s = _mdns_server->services;
uint16_t service_num = 0;
while (s) {
service_num ++;
s = s->next;
if (service_num >= MDNS_MAX_SERVICES) {
return false;
}
}
return true;
}
esp_err_t _mdns_send_rx_action(mdns_rx_packet_t * packet)
{
mdns_action_t * action = NULL;
@ -4124,6 +4139,11 @@ esp_err_t mdns_service_add(const char * instance, const char * service, const ch
if (!_mdns_server || _str_null_or_empty(service) || _str_null_or_empty(proto) || !port) {
return ESP_ERR_INVALID_ARG;
}
if (!_mdns_can_add_more_services()) {
return ESP_ERR_NO_MEM;
}
mdns_srv_item_t * item = _mdns_get_service_item(service, proto);
if (item) {
return ESP_ERR_INVALID_ARG;

View File

@ -20,6 +20,9 @@
#define _mdns_dbg_printf(...) printf(__VA_ARGS__)
#endif
/** The maximum number of services */
#define MDNS_MAX_SERVICES CONFIG_MDNS_MAX_SERVICES
#define MDNS_ANSWER_PTR_TTL 4500
#define MDNS_ANSWER_TXT_TTL 4500
#define MDNS_ANSWER_SRV_TTL 120