| 61 | } |
| 62 | |
| 63 | bool TcpConnection::connect(const String& server, int port, bool useSsl) |
| 64 | { |
| 65 | if(tcp == nullptr) { |
| 66 | auto tcpNew = tcp_new(); |
| 67 | if(tcpNew == nullptr) { |
| 68 | debug_e("Out of TCP connections"); |
| 69 | return false; |
| 70 | } |
| 71 | initialize(tcpNew); |
| 72 | } |
| 73 | |
| 74 | ip_addr_t addr; |
| 75 | |
| 76 | this->useSsl = useSsl; |
| 77 | if(useSsl) { |
| 78 | if(!sslCreateSession()) { |
| 79 | return false; |
| 80 | } |
| 81 | ssl->hostName = server; |
| 82 | } |
| 83 | |
| 84 | debug_tcp_d("connect to \"%s:%d\"", server.c_str(), port); |
| 85 | canSend = false; // Wait for connection |
| 86 | |
| 87 | struct DnsLookup { |
| 88 | TcpConnection* con; |
| 89 | int port; |
| 90 | }; |
| 91 | DnsLookup* look = new DnsLookup{this, port}; |
| 92 | err_t dnslook = dns_gethostbyname( |
| 93 | server.c_str(), &addr, |
| 94 | [](const char* name, LWIP_IP_ADDR_T* ipaddr, void* arg) { |
| 95 | auto dlook = static_cast<DnsLookup*>(arg); |
| 96 | if(dlook != nullptr) { |
| 97 | dlook->con->internalOnDnsResponse(name, ipaddr, dlook->port); |
| 98 | delete dlook; |
| 99 | } |
| 100 | }, |
| 101 | look); |
| 102 | if(dnslook == ERR_INPROGRESS) { |
| 103 | // Operation pending - see internalOnDnsResponse() |
| 104 | return true; |
| 105 | } |
| 106 | delete look; |
| 107 | |
| 108 | return (dnslook == ERR_OK) ? internalConnect(addr, port) : false; |
| 109 | } |
| 110 | |
| 111 | bool TcpConnection::connect(IpAddress addr, uint16_t port, bool useSsl) |
| 112 | { |
nothing calls this directly
no test coverage detected