From f5f71a03655acbea59331f80bc4e12fbf2d01334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Thu, 24 May 2018 11:57:12 -0400 Subject: [PATCH] log: fix LogMethod copy --- include/opendht/log_enable.h | 17 ++++++++++++++++- include/opendht/securedht.h | 2 +- src/dht_proxy_client.cpp | 3 ++- src/dhtrunner.cpp | 4 ++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/opendht/log_enable.h b/include/opendht/log_enable.h index 7310de54..dac3863d 100644 --- a/include/opendht/log_enable.h +++ b/include/opendht/log_enable.h @@ -43,8 +43,23 @@ inline void NOLOG(char const*, va_list) {} struct LogMethod { LogMethod() = default; + LogMethod(LogMethod&& l) : func(std::move(l.func)) {} + LogMethod(const LogMethod& l) : func(l.func) {} + + LogMethod& operator=(dht::LogMethod&& l) { + func = std::forward(l.func); + return *this; + } + LogMethod& operator=(const dht::LogMethod& l) { + func = l.func; + return *this; + } + template - LogMethod(T&& t) : func(std::forward(t)) {} + explicit LogMethod(T&& t) : func(std::forward(t)) {} + + template + LogMethod(const T& t) : func(t) {} void operator()(char const* format, ...) const { va_list args; diff --git a/include/opendht/securedht.h b/include/opendht/securedht.h index f5382708..e1049cd8 100644 --- a/include/opendht/securedht.h +++ b/include/opendht/securedht.h @@ -315,7 +315,7 @@ public: DHT_LOG.DEBUG = debug; DHT_LOG.WARN = warn; DHT_LOG.ERR = error; - dht_->setLoggers(std::forward(error), std::forward(warn), std::forward(debug)); + dht_->setLoggers(error, warn, debug); } /** diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index a099992d..94ccb86a 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -571,13 +571,14 @@ DhtProxyClient::getProxyInfos() void DhtProxyClient::onProxyInfos(const Json::Value& proxyInfos, sa_family_t family) { - DHT_LOG.d("Got proxy infos %s", family == AF_INET ? "IPv4" : "IPv6"); std::lock_guard l(lockCurrentProxyInfos_); auto oldStatus = std::max(statusIpv4_, statusIpv6_); auto& status = family == AF_INET ? statusIpv4_ : statusIpv6_; if (not proxyInfos.isMember("node_id")) { + DHT_LOG.e("Proxy info request failed for %s", family == AF_INET ? "IPv4" : "IPv6"); status = NodeStatus::Disconnected; } else { + DHT_LOG.d("Got proxy reply for %s", family == AF_INET ? "IPv4" : "IPv6"); try { myid = InfoHash(proxyInfos["node_id"].asString()); stats4_ = NodeStats(proxyInfos["ipv4"]); diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp index c8e564fa..04381464 100644 --- a/src/dhtrunner.cpp +++ b/src/dhtrunner.cpp @@ -247,10 +247,10 @@ void DhtRunner::setLoggers(LogMethod error, LogMethod warn, LogMethod debug) { std::lock_guard lck(dht_mtx); if (dht_) - dht_->setLoggers(std::forward(error), std::forward(warn), std::forward(debug)); + dht_->setLoggers(error, warn, debug); #if OPENDHT_PROXY_CLIENT if (dht_via_proxy_) - dht_via_proxy_->setLoggers(std::forward(error), std::forward(warn), std::forward(debug)); + dht_via_proxy_->setLoggers(error, warn, debug); #endif }