Cleanup nano::transport::establish_tcp
Removes usage of start_tcp callback and replace it with simple polling for an established connection.
This commit is contained in:
parent
4e2ffe9993
commit
ce29ba079f
1 changed files with 7 additions and 15 deletions
|
|
@ -8,27 +8,19 @@
|
|||
#include <chrono>
|
||||
#include <future>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
std::shared_ptr<nano::transport::channel_tcp> nano::establish_tcp (nano::system & system, nano::node & node, nano::endpoint const & endpoint)
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
debug_assert (node.network.endpoint () != endpoint && "Establishing TCP to self is not allowed");
|
||||
|
||||
std::shared_ptr<nano::transport::channel_tcp> result;
|
||||
debug_assert (!node.flags.disable_tcp_realtime);
|
||||
std::promise<std::shared_ptr<nano::transport::channel>> promise;
|
||||
auto callback = [&promise] (std::shared_ptr<nano::transport::channel> channel_a) { promise.set_value (channel_a); };
|
||||
auto future = promise.get_future ();
|
||||
node.network.tcp_channels.start_tcp (endpoint, callback);
|
||||
auto error = system.poll_until_true (2s, [&future] { return future.wait_for (0s) == std::future_status::ready; });
|
||||
if (!error)
|
||||
{
|
||||
auto channel = future.get ();
|
||||
EXPECT_NE (nullptr, channel);
|
||||
if (channel)
|
||||
{
|
||||
result = node.network.tcp_channels.find_channel (channel->get_tcp_endpoint ());
|
||||
}
|
||||
}
|
||||
node.network.tcp_channels.start_tcp (endpoint);
|
||||
auto error = system.poll_until_true (2s, [&result, &node, &endpoint] {
|
||||
result = node.network.tcp_channels.find_channel (nano::transport::map_endpoint_to_tcp (endpoint));
|
||||
return result != nullptr;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue