Skip to content

Commit

Permalink
GH-835 Reuse connection
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Sep 30, 2024
1 parent 8d9887e commit f5fa00a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4719,7 +4719,31 @@ namespace eosio {
auto& index = connections.get<by_connection>();
index.erase(c);
}
resolve_and_connect(c->peer_address(), c->listen_address, c->consecutive_immediate_connection_close.load());

auto [host, port, type] = split_host_port_type(c->peer_address());
c->strand.post([this, c, host, port]() {
auto resolver = std::make_shared<tcp::resolver>( my_impl->thread_pool.get_executor() );
resolver->async_resolve(host, port, boost::asio::bind_executor(c->strand,
[this, resolver, c, host, port]
( const boost::system::error_code& err, const tcp::resolver::results_type& results ) {
c->set_heartbeat_timeout( heartbeat_timeout );
{
std::lock_guard g( connections_mtx );
connections.emplace( connection_detail{
.host = c->peer_address(),
.c = c,
});
}
if( !err ) {
c->connect( results );
} else {
fc_wlog( logger, "Unable to resolve ${host}:${port} ${error}",
("host", host)("port", port)( "error", err.message() ) );
c->set_state(connection::connection_state::closed);
++c->consecutive_immediate_connection_close;
}
}) );
});
}

// called by API
Expand Down

0 comments on commit f5fa00a

Please sign in to comment.