mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 10:17:30 +02:00
mdns: Add asynchronous query API
Closes https://github.com/espressif/esp-idf/issues/7090 * Original commit: espressif/esp-idf@d81482d699
This commit is contained in:
committed by
suren-gabrielyan-espressif
parent
40da0d29be
commit
47c7266103
@ -5292,6 +5292,52 @@ void mdns_query_results_free(mdns_result_t * results)
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t mdns_query_async_delete(mdns_search_once_t* search)
|
||||
{
|
||||
if (!search) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (search->state != SEARCH_OFF) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
MDNS_SERVICE_LOCK();
|
||||
_mdns_search_free(search);
|
||||
MDNS_SERVICE_UNLOCK();
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool mdns_query_async_get_results(mdns_search_once_t* search, uint32_t timeout, mdns_result_t ** results)
|
||||
{
|
||||
if (xSemaphoreTake(search->done_semaphore, pdMS_TO_TICKS(timeout)) == pdTRUE) {
|
||||
*results = search->result;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
mdns_search_once_t* mdns_query_async_new(const char * name, const char * service, const char * proto, uint16_t type, uint32_t timeout, size_t max_results)
|
||||
{
|
||||
mdns_search_once_t *search = NULL;
|
||||
|
||||
if (!_mdns_server || !timeout || _str_null_or_empty(service) != _str_null_or_empty(proto)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
search = _mdns_search_init(name, service, proto, type, timeout, max_results);
|
||||
if (!search) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (_mdns_send_search_action(ACTION_SEARCH_ADD, search)) {
|
||||
_mdns_search_free(search);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return search;
|
||||
}
|
||||
|
||||
esp_err_t mdns_query(const char * name, const char * service, const char * proto, uint16_t type, uint32_t timeout, size_t max_results, mdns_result_t ** results)
|
||||
{
|
||||
mdns_search_once_t * search = NULL;
|
||||
|
Reference in New Issue
Block a user