Skip to content

Commit a924420

Browse files
authored
Fix Issue that connect() did not work with DNS
Add additional code to "bool AsyncClient::connect(const char* host, uint16_t port)" and "static void _handle_async_event(lwip_event_packet_t * e)". Async Service task and queue had not yet been started and "LWIP_TCP_DNS" had no handler defined, so "_tcp_dns_found" called by "dns_gethostbyname" ran into an error.
1 parent d1f28ff commit a924420

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/AsyncTCP.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ static void _handle_async_event(lwip_event_packet_t * e){
161161
} else if(e->event == LWIP_TCP_ACCEPT){
162162
//ets_printf("A: 0x%08x 0x%08x\n", e->arg, e->accept.client);
163163
AsyncServer::_s_accepted(e->arg, e->accept.client);
164+
} else if(e->event == LWIP_TCP_DNS){
165+
//ets_printf("D: 0x%08x %s = %s\n", e->arg, e->dns.name, ipaddr_ntoa(&e->dns.addr));
166+
AsyncClient::_s_dns_found(e->dns.name, &e->dns.addr, e->arg);
164167
}
165168
free((void*)(e));
166169
}
@@ -674,6 +677,13 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){
674677

675678
bool AsyncClient::connect(const char* host, uint16_t port){
676679
ip_addr_t addr;
680+
681+
if(!_start_async_task()){
682+
Serial.println("failed to start task");
683+
log_e("failed to start task");
684+
return false;
685+
}
686+
677687
err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_tcp_dns_found, this);
678688
if(err == ERR_OK) {
679689
return connect(IPAddress(addr.u_addr.ip4.addr), port);

0 commit comments

Comments
 (0)