mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 10:37:37 -07:00
Quicker resource cleanup on p2p socks timeout
This commit is contained in:
parent
2d3ce2d64a
commit
2a8a51129f
@ -201,6 +201,13 @@ namespace socks
|
|||||||
std::shared_ptr<client> self_;
|
std::shared_ptr<client> self_;
|
||||||
void operator()(boost::system::error_code error = boost::system::error_code{});
|
void operator()(boost::system::error_code error = boost::system::error_code{});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! Calls `async_close` on `self` at destruction. NOP if `nullptr`.
|
||||||
|
struct close_on_exit
|
||||||
|
{
|
||||||
|
std::shared_ptr<client> self;
|
||||||
|
~close_on_exit() { async_close{std::move(self)}(); }
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Handler>
|
template<typename Handler>
|
||||||
|
@ -339,6 +339,7 @@ namespace nodetool
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
net::socks::client::close_on_exit close_client{};
|
||||||
boost::unique_future<client_result> socks_result{};
|
boost::unique_future<client_result> socks_result{};
|
||||||
{
|
{
|
||||||
boost::promise<client_result> socks_promise{};
|
boost::promise<client_result> socks_promise{};
|
||||||
@ -347,6 +348,7 @@ namespace nodetool
|
|||||||
auto client = net::socks::make_connect_client(
|
auto client = net::socks::make_connect_client(
|
||||||
boost::asio::ip::tcp::socket{service}, net::socks::version::v4a, notify{std::move(socks_promise)}
|
boost::asio::ip::tcp::socket{service}, net::socks::version::v4a, notify{std::move(socks_promise)}
|
||||||
);
|
);
|
||||||
|
close_client.self = client;
|
||||||
if (!start_socks(std::move(client), proxy, remote))
|
if (!start_socks(std::move(client), proxy, remote))
|
||||||
return boost::none;
|
return boost::none;
|
||||||
}
|
}
|
||||||
@ -368,7 +370,10 @@ namespace nodetool
|
|||||||
{
|
{
|
||||||
auto result = socks_result.get();
|
auto result = socks_result.get();
|
||||||
if (!result.first)
|
if (!result.first)
|
||||||
|
{
|
||||||
|
close_client.self.reset();
|
||||||
return {std::move(result.second)};
|
return {std::move(result.second)};
|
||||||
|
}
|
||||||
|
|
||||||
MERROR("Failed to make socks connection to " << remote.str() << " (via " << proxy << "): " << result.first.message());
|
MERROR("Failed to make socks connection to " << remote.str() << " (via " << proxy << "): " << result.first.message());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user