Skip to content

Commit

Permalink
Merge pull request #50 from obrain17/master
Browse files Browse the repository at this point in the history
Fix Issue that connect() did not work with DNS
  • Loading branch information
me-no-dev committed Jul 7, 2019
2 parents d1f28ff + a924420 commit 90715ae
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/AsyncTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ static void _handle_async_event(lwip_event_packet_t * e){
} else if(e->event == LWIP_TCP_ACCEPT){
//ets_printf("A: 0x%08x 0x%08x\n", e->arg, e->accept.client);
AsyncServer::_s_accepted(e->arg, e->accept.client);
} else if(e->event == LWIP_TCP_DNS){
//ets_printf("D: 0x%08x %s = %s\n", e->arg, e->dns.name, ipaddr_ntoa(&e->dns.addr));
AsyncClient::_s_dns_found(e->dns.name, &e->dns.addr, e->arg);
}
free((void*)(e));
}
Expand Down Expand Up @@ -674,6 +677,13 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){

bool AsyncClient::connect(const char* host, uint16_t port){
ip_addr_t addr;

if(!_start_async_task()){
Serial.println("failed to start task");
log_e("failed to start task");
return false;
}

err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_tcp_dns_found, this);
if(err == ERR_OK) {
return connect(IPAddress(addr.u_addr.ip4.addr), port);
Expand Down

0 comments on commit 90715ae

Please sign in to comment.