in src/TcpAdapterProxy.cpp [1663:1706]
void tcp_adapter_proxy::async_resolve_destination_for_connect(tcp_adapter_context &tac, std::shared_ptr<basic_retry_config> retry_config, string const & service_id, boost::system::error_code const &ec, tcp::resolver::results_type results)
{
BOOST_LOG_SEV(log, trace) << "Resolve destination to connect for service id: " << service_id;
if (ec)
{
string endpoint = tac.adapter_config.serviceId_to_endpoint_map[service_id];
BOOST_LOG_SEV(log, error) << (boost::format("Could not resolve endpoint %1%. Error message: %2%") % endpoint % ec.message()).str();
basic_retry_execute(log, retry_config,
[this, &tac, service_id]()
{
tcp_connection::pointer socket_connection = get_tcp_connection(tac, service_id);
socket_connection->after_send_message = std::bind(&tcp_adapter_proxy::setup_tcp_socket, this, std::ref(tac), service_id);
async_send_stream_reset(tac, service_id);
});
}
else {
tcp_client::pointer client = tac.serviceId_to_tcp_client_map[service_id];
std::string dst_host = results->endpoint().address().to_string();
unsigned short dst_port = results->endpoint().port();
BOOST_LOG_SEV(log, debug) << "Resolved destination host to IP: " << dst_host << " , connecting ...";
client->connection_->socket().async_connect(*results.begin(),
[=, &tac](boost::system::error_code const &ec)
{
if (ec)
{
BOOST_LOG_SEV(log, error) << (boost::format("Could not connect to destination %1%:%2% -- %3%") % dst_host % dst_host % ec.message()).str();
basic_retry_execute(log, retry_config,
[this, &tac, service_id]()
{
tcp_connection::pointer socket_connection = get_tcp_connection(tac, service_id);
socket_connection->after_send_message = std::bind(&tcp_adapter_proxy::setup_tcp_socket, this, std::ref(tac), service_id);
async_send_stream_reset(tac, service_id);
});
}
else
{
BOOST_LOG_SEV(log, info) << "Connected to " << dst_host << ", port: " << dst_port;
tcp_client::pointer client = tac.serviceId_to_tcp_client_map[service_id];
invoke_and_clear_handler(client->after_setup_tcp_socket);
}
}
);
}
}