mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
ESP8266WiFi: support timeout for WiFi.hostByName
This commit is contained in:
parent
85078f47a0
commit
2aeac91c90
@ -426,6 +426,8 @@ void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback
|
|||||||
void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
|
void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool _dns_lookup_pending = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve the given hostname to an IP address.
|
* Resolve the given hostname to an IP address.
|
||||||
* @param aHostname Name to be resolved
|
* @param aHostname Name to be resolved
|
||||||
@ -433,7 +435,14 @@ void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *ca
|
|||||||
* @return 1 if aIPAddrString was successfully converted to an IP address,
|
* @return 1 if aIPAddrString was successfully converted to an IP address,
|
||||||
* else error code
|
* else error code
|
||||||
*/
|
*/
|
||||||
int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult) {
|
int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult)
|
||||||
|
{
|
||||||
|
return hostByName(aHostname, aResult, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms)
|
||||||
|
{
|
||||||
ip_addr_t addr;
|
ip_addr_t addr;
|
||||||
aResult = static_cast<uint32_t>(0);
|
aResult = static_cast<uint32_t>(0);
|
||||||
|
|
||||||
@ -448,7 +457,9 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
|
|||||||
if(err == ERR_OK) {
|
if(err == ERR_OK) {
|
||||||
aResult = addr.addr;
|
aResult = addr.addr;
|
||||||
} else if(err == ERR_INPROGRESS) {
|
} else if(err == ERR_INPROGRESS) {
|
||||||
esp_yield();
|
_dns_lookup_pending = true;
|
||||||
|
delay(timeout_ms);
|
||||||
|
_dns_lookup_pending = false;
|
||||||
// will return here when dns_found_callback fires
|
// will return here when dns_found_callback fires
|
||||||
if(aResult != 0) {
|
if(aResult != 0) {
|
||||||
err = ERR_OK;
|
err = ERR_OK;
|
||||||
@ -477,6 +488,9 @@ void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *ca
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
(void) name;
|
(void) name;
|
||||||
|
if (!_dns_lookup_pending) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(ipaddr) {
|
if(ipaddr) {
|
||||||
(*reinterpret_cast<IPAddress*>(callback_arg)) = ipaddr->addr;
|
(*reinterpret_cast<IPAddress*>(callback_arg)) = ipaddr->addr;
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,7 @@ class ESP8266WiFiGenericClass {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
int hostByName(const char* aHostname, IPAddress& aResult);
|
int hostByName(const char* aHostname, IPAddress& aResult);
|
||||||
|
int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user