From 8593089cb6ebdba9fbcaf10e09c9bb86c9749d39 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Thu, 9 Jan 2025 08:14:29 +1000 Subject: [PATCH] Another attempt to use more advanced boost in the examples. --- examples/client/Client.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/client/Client.cpp b/examples/client/Client.cpp index 7d42487..e3febe2 100644 --- a/examples/client/Client.cpp +++ b/examples/client/Client.cpp @@ -34,14 +34,19 @@ bool Client::start() { boost::asio::ip::tcp::resolver resolver(m_io); boost::system::error_code ec; - auto iter = resolver.resolve(m_server, std::to_string(m_port), ec); + auto resolveResult = resolver.resolve(m_server, std::to_string(m_port), ec); if (ec) { std::cerr << "ERROR: Failed to resolve \"" << m_server << ':' << m_port << "\" " << "with error: " << ec.message() << std::endl; return false; } - auto endpoint = iter->endpoint(); + if (resolveResult.empty()) { + std::cerr << "ERROR: No resolution result" << std::endl; + return false; + } + + auto endpoint = resolveResult.begin()->endpoint(); m_socket.connect(endpoint, ec); if (ec) { std::cerr << "ERROR: Failed to connect to \"" << endpoint << "\" " <<