@@ -426,14 +426,23 @@ void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback
426426void wifi_dns_found_callback (const char *name, const ip_addr_t *ipaddr, void *callback_arg);
427427#endif
428428
429+ static bool _dns_lookup_pending = false ;
430+
429431/* *
430432 * Resolve the given hostname to an IP address.
431433 * @param aHostname Name to be resolved
432434 * @param aResult IPAddress structure to store the returned IP address
433435 * @return 1 if aIPAddrString was successfully converted to an IP address,
434436 * else error code
435437 */
436- int ESP8266WiFiGenericClass::hostByName (const char * aHostname, IPAddress& aResult) {
438+ int ESP8266WiFiGenericClass::hostByName (const char * aHostname, IPAddress& aResult)
439+ {
440+ return hostByName (aHostname, aResult, 10000 );
441+ }
442+
443+
444+ int ESP8266WiFiGenericClass::hostByName (const char * aHostname, IPAddress& aResult, uint32_t timeout_ms)
445+ {
437446 ip_addr_t addr;
438447 aResult = static_cast <uint32_t >(0 );
439448
@@ -448,7 +457,9 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
448457 if (err == ERR_OK) {
449458 aResult = addr.addr ;
450459 } else if (err == ERR_INPROGRESS) {
451- esp_yield ();
460+ _dns_lookup_pending = true ;
461+ delay (timeout_ms);
462+ _dns_lookup_pending = false ;
452463 // will return here when dns_found_callback fires
453464 if (aResult != 0 ) {
454465 err = ERR_OK;
@@ -477,6 +488,9 @@ void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *ca
477488#endif
478489{
479490 (void ) name;
491+ if (!_dns_lookup_pending) {
492+ return ;
493+ }
480494 if (ipaddr) {
481495 (*reinterpret_cast <IPAddress*>(callback_arg)) = ipaddr->addr ;
482496 }
0 commit comments