diff --git a/webcc/client.cc b/webcc/client.cc index b6fe4dc..4588656 100644 --- a/webcc/client.cc +++ b/webcc/client.cc @@ -99,6 +99,8 @@ void Client::DoConnect(RequestPtr request, const std::string& default_port) { port = default_port; } + LOG_VERB("Resolve host (%s)...", request->host().c_str()); + std::error_code ec; auto endpoints = resolver.resolve(tcp::v4(), request->host(), port, ec); diff --git a/webcc/utility.cc b/webcc/utility.cc index ca3cd66..936d226 100644 --- a/webcc/utility.cc +++ b/webcc/utility.cc @@ -5,6 +5,7 @@ #include #include #include // for put_time +#include #include #include "webcc/string.h" @@ -72,5 +73,21 @@ void DumpByLine(const std::string& data, std::ostream& os, } } +void PrintEndpoint(std::ostream& ostream, + const asio::ip::tcp::endpoint& endpoint) { + ostream << endpoint; + if (endpoint.protocol() == asio::ip::tcp::v4()) { + ostream << ", v4"; + } else if (endpoint.protocol() == asio::ip::tcp::v6()) { + ostream << ", v6"; + } +} + +std::string EndpointToString(const asio::ip::tcp::endpoint& endpoint) { + std::stringstream ss; + PrintEndpoint(ss, endpoint); + return ss.str(); +} + } // namespace utility } // namespace webcc diff --git a/webcc/utility.h b/webcc/utility.h index d0c7825..036a296 100644 --- a/webcc/utility.h +++ b/webcc/utility.h @@ -1,8 +1,11 @@ #ifndef WEBCC_UTILITY_H_ #define WEBCC_UTILITY_H_ +#include #include +#include "asio/ip/tcp.hpp" + #include "webcc/globals.h" // Avoid include in the header. @@ -35,6 +38,14 @@ bool ReadFile(const std::filesystem::path& path, std::string* output); void DumpByLine(const std::string& data, std::ostream& os, const std::string& prefix); +// Print TCP endpoint. +// Usage: PrintEndpoint(std::cout, endpoint) +void PrintEndpoint(std::ostream& ostream, + const asio::ip::tcp::endpoint& endpoint); + +// TCP endpoint to string. +std::string EndpointToString(const asio::ip::tcp::endpoint& endpoint); + } // namespace utility } // namespace webcc