@@ -426,14 +426,23 @@ void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback
426
426
void wifi_dns_found_callback (const char *name, const ip_addr_t *ipaddr, void *callback_arg);
427
427
#endif
428
428
429
+ static bool _dns_lookup_pending = false ;
430
+
429
431
/* *
430
432
* Resolve the given hostname to an IP address.
431
433
* @param aHostname Name to be resolved
432
434
* @param aResult IPAddress structure to store the returned IP address
433
435
* @return 1 if aIPAddrString was successfully converted to an IP address,
434
436
* else error code
435
437
*/
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
+ {
437
446
ip_addr_t addr;
438
447
aResult = static_cast <uint32_t >(0 );
439
448
@@ -448,7 +457,9 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
448
457
if (err == ERR_OK) {
449
458
aResult = addr.addr ;
450
459
} else if (err == ERR_INPROGRESS) {
451
- esp_yield ();
460
+ _dns_lookup_pending = true ;
461
+ delay (timeout_ms);
462
+ _dns_lookup_pending = false ;
452
463
// will return here when dns_found_callback fires
453
464
if (aResult != 0 ) {
454
465
err = ERR_OK;
@@ -477,6 +488,9 @@ void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *ca
477
488
#endif
478
489
{
479
490
(void ) name;
491
+ if (!_dns_lookup_pending) {
492
+ return ;
493
+ }
480
494
if (ipaddr) {
481
495
(*reinterpret_cast <IPAddress*>(callback_arg)) = ipaddr->addr ;
482
496
}
0 commit comments