add endpoint print functions
This commit is contained in:
@@ -99,6 +99,8 @@ void Client::DoConnect(RequestPtr request, const std::string& default_port) {
|
|||||||
port = default_port;
|
port = default_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_VERB("Resolve host (%s)...", request->host().c_str());
|
||||||
|
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
auto endpoints = resolver.resolve(tcp::v4(), request->host(), port, ec);
|
auto endpoints = resolver.resolve(tcp::v4(), request->host(), port, ec);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip> // for put_time
|
#include <iomanip> // for put_time
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "webcc/string.h"
|
#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 utility
|
||||||
} // namespace webcc
|
} // namespace webcc
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
#ifndef WEBCC_UTILITY_H_
|
#ifndef WEBCC_UTILITY_H_
|
||||||
#define WEBCC_UTILITY_H_
|
#define WEBCC_UTILITY_H_
|
||||||
|
|
||||||
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "asio/ip/tcp.hpp"
|
||||||
|
|
||||||
#include "webcc/globals.h"
|
#include "webcc/globals.h"
|
||||||
|
|
||||||
// Avoid include <filesystem> in the header.
|
// Avoid include <filesystem> 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,
|
void DumpByLine(const std::string& data, std::ostream& os,
|
||||||
const std::string& prefix);
|
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 utility
|
||||||
} // namespace webcc
|
} // namespace webcc
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user