Misc logging improvements

This commit is contained in:
Henrik Rydgård
2020-12-19 20:31:58 +01:00
parent e6c3d72226
commit 05bfac0ef0
2 changed files with 24 additions and 11 deletions
+15 -2
View File
@@ -48,6 +48,19 @@ inline unsigned short myhtons(unsigned short x) {
return (x >> 8) | (x << 8);
}
const char *DNSTypeAsString(DNSType type) {
switch (type) {
case DNSType::IPV4:
return "IPV4";
case DNSType::IPV6:
return "IPV6";
case DNSType::ANY:
return "ANY";
default:
return "N/A";
}
}
bool Connection::Resolve(const char *host, int port, DNSType type) {
if ((intptr_t)sock_ != -1) {
ERROR_LOG(IO, "Resolve: Already have a socket");
@@ -66,8 +79,8 @@ bool Connection::Resolve(const char *host, int port, DNSType type) {
std::string err;
if (!net::DNSResolve(host, port_str, &resolved_, err, type)) {
ERROR_LOG(IO, "Failed to resolve host %s: %s", host, err.c_str());
// So that future calls fail.
WARN_LOG(IO, "Failed to resolve host '%s': '%s' (%s)", host, err.c_str(), DNSTypeAsString(type));
// Zero port so that future calls fail.
port_ = 0;
return false;
}