mirror of
https://github.com/espressif/esp-lwip.git
synced 2026-09-01 06:40:13 +00:00
optimization lwip dns timer
This commit is contained in:
@@ -94,6 +94,12 @@
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/prot/dns.h"
|
||||
#include "lwip/timeouts.h"
|
||||
|
||||
#if ESP_LWIP_DNS_TIMERS_ONDEMAND
|
||||
#include "stdbool.h"
|
||||
static bool is_tmr_start = false;
|
||||
#endif /* ESP_LWIP_DNS_TIMERS_ONDEMAND */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -422,6 +428,17 @@ dns_getserver(u8_t numdns)
|
||||
}
|
||||
}
|
||||
|
||||
#if ESP_LWIP_DNS_TIMERS_ONDEMAND
|
||||
/**
|
||||
* Wrapper function with matching prototype which calls the actual callback
|
||||
*/
|
||||
static void dns_timeout_cb(void *arg)
|
||||
{
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
dns_tmr();
|
||||
}
|
||||
#endif /* ESP_LWIP_DNS_TIMERS_ONDEMAND */
|
||||
|
||||
/**
|
||||
* The DNS resolver client timer - handle retries and timeouts and should
|
||||
* be called every DNS_TMR_INTERVAL milliseconds (every second by default).
|
||||
@@ -429,8 +446,25 @@ dns_getserver(u8_t numdns)
|
||||
void
|
||||
dns_tmr(void)
|
||||
{
|
||||
#if ESP_LWIP_DNS_TIMERS_ONDEMAND
|
||||
bool tmr_restart = false;
|
||||
#endif /* ESP_LWIP_DNS_TIMERS_ONDEMAND */
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_tmr: dns_check_entries\n"));
|
||||
dns_check_entries();
|
||||
#if ESP_LWIP_DNS_TIMERS_ONDEMAND
|
||||
for (u8_t i = 0; i < DNS_TABLE_SIZE; ++i) {
|
||||
if (dns_table[i].state != DNS_STATE_UNUSED) {
|
||||
tmr_restart = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tmr_restart) {
|
||||
sys_timeout(DNS_TMR_INTERVAL, dns_timeout_cb, NULL);
|
||||
} else {
|
||||
sys_untimeout(dns_timeout_cb, NULL);
|
||||
is_tmr_start = false;
|
||||
}
|
||||
#endif/* ESP_LWIP_DNS_TIMERS_ONDEMAND */
|
||||
}
|
||||
|
||||
#if DNS_LOCAL_HOSTLIST
|
||||
@@ -1542,6 +1576,12 @@ dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found,
|
||||
|
||||
/* force to send query without waiting timer */
|
||||
dns_check_entry(i);
|
||||
#if ESP_LWIP_DNS_TIMERS_ONDEMAND
|
||||
if (!is_tmr_start) {
|
||||
sys_timeout(DNS_TMR_INTERVAL, dns_timeout_cb, NULL);
|
||||
is_tmr_start = true;
|
||||
}
|
||||
#endif /* ESP_LWIP_DNS_TIMERS_ONDEMAND */
|
||||
|
||||
/* dns query is enqueued */
|
||||
return ERR_INPROGRESS;
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ const struct lwip_cyclic_timer lwip_cyclic_timers[] = {
|
||||
{IGMP_TMR_INTERVAL, HANDLER(igmp_tmr)},
|
||||
#endif /* LWIP_IGMP */
|
||||
#endif /* LWIP_IPV4 */
|
||||
#if LWIP_DNS
|
||||
#if LWIP_DNS && !ESP_LWIP_DNS_TIMERS_ONDEMAND
|
||||
{DNS_TMR_INTERVAL, HANDLER(dns_tmr)},
|
||||
#endif /* LWIP_DNS */
|
||||
#if LWIP_IPV6
|
||||
|
||||
@@ -102,6 +102,7 @@
|
||||
#define ESP_PPP 1
|
||||
#define ESP_LWIP_IGMP_TIMERS_ONDEMAND 1
|
||||
#define ESP_LWIP_MLD6_TIMERS_ONDEMAND 1
|
||||
#define ESP_LWIP_DNS_TIMERS_ONDEMAND 1
|
||||
#define ESP_GRATUITOUS_ARP 1
|
||||
#define ESP_LWIP_SELECT 1
|
||||
#define ESP_LWIP_LOCK 1
|
||||
|
||||
Reference in New Issue
Block a user