mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
speed up WiFi.hostByName when the hostname is actually a IP.
This commit is contained in:
parent
127f05da9f
commit
3e9dede14e
@ -316,15 +316,32 @@ void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback
|
||||
int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult) {
|
||||
ip_addr_t addr;
|
||||
aResult = static_cast<uint32_t>(0);
|
||||
|
||||
if(aResult.fromString(aHostname)) {
|
||||
// Host name is a IP address use it!
|
||||
DEBUG_WIFI_GENERIC("[hostByName] Host: %s is a IP!\n", aHostname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname);
|
||||
err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
|
||||
if(err == ERR_OK) {
|
||||
aResult = addr.addr;
|
||||
} else if(err == ERR_INPROGRESS) {
|
||||
esp_yield();
|
||||
// will return here when dns_found_callback fires
|
||||
if(aResult != 0) {
|
||||
err = ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return (aResult != 0) ? 1 : 0;
|
||||
if(err != 0) {
|
||||
DEBUG_WIFI_GENERIC("[hostByName] Host: %s lookup error: %d!\n", aHostname, err);
|
||||
} else {
|
||||
DEBUG_WIFI_GENERIC("[hostByName] Host: %s IP: %s\n", aHostname, aResult.toString().c_str());
|
||||
}
|
||||
|
||||
return (err == ERR_OK) ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,16 @@
|
||||
|
||||
#include "ESP8266WiFiType.h"
|
||||
|
||||
#ifdef DEBUG_ESP_WIFI
|
||||
#ifdef DEBUG_ESP_PORT
|
||||
#define DEBUG_WIFI_GENERIC(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DEBUG_WIFI_GENERIC
|
||||
#define DEBUG_WIFI_GENERIC(...)
|
||||
#endif
|
||||
|
||||
typedef void (*WiFiEventCb)(WiFiEvent_t event);
|
||||
|
||||
typedef struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user