From: Rosen Penev Date: Wed, 6 May 2020 02:55:52 +0000 (-0700) Subject: replace boost:bind() with lambdas X-Git-Tag: rec-4.4.0-beta1~22^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a88c05b22830d42882a76de2c755beba285d01c0;p=thirdparty%2Fpdns.git replace boost:bind() with lambdas lambdas are standard C++. bind is also recommended against by LLVM. Signed-off-by: Rosen Penev --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 712c9cc6cb..431ae994ce 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2846,7 +2846,8 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var) } if(g_weDistributeQueries) { - distributeAsyncFunction(data, boost::bind(doProcessUDPQuestion, data, fromaddr, dest, source, destination, tv, fd, proxyProtocolValues)); + distributeAsyncFunction(data, [data = data, fromaddr, dest, source, destination, tv, fd, proxyProtocolValues]() mutable + { return doProcessUDPQuestion(data, fromaddr, dest, source, destination, tv, fd, proxyProtocolValues); }); } else { ++s_threadInfos[t_id].numberOfDistributedQueries; @@ -3516,7 +3517,7 @@ template T broadcastAccFunction(const boost::function& func) const auto& tps = threadInfo.pipes; ThreadMSG* tmsg = new ThreadMSG(); - tmsg->func = boost::bind(voider, func); + tmsg->func = [func]{ return voider(func); }; tmsg->wantAnswer = true; if(write(tps.writeToThread, &tmsg, sizeof(tmsg)) != sizeof(tmsg)) { @@ -3806,7 +3807,7 @@ catch(PDNSException& ae) string doTraceRegex(vector::const_iterator begin, vector::const_iterator end) { - return broadcastAccFunction(boost::bind(pleaseUseNewTraceRegex, begin!=end ? *begin : "")); + return broadcastAccFunction([=]{ return pleaseUseNewTraceRegex(begin!=end ? *begin : ""); }); } static void checkLinuxIPv6Limits() @@ -3927,7 +3928,7 @@ void parseACLs() } g_initialAllowFrom = allowFrom; - broadcastFunction(boost::bind(pleaseSupplantACLs, allowFrom)); + broadcastFunction([=]{ return pleaseSupplantACLs(allowFrom); }); oldAllowFrom = nullptr; l_initialized = true; diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 489e81083f..a3bc85bb4d 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -250,7 +250,7 @@ static string doDumpNSSpeeds(T begin, T end) return "Error opening dump file for writing: "+stringerror()+"\n"; uint64_t total = 0; try { - total = broadcastAccFunction(boost::bind(pleaseDumpNSSpeeds, fd)); + total = broadcastAccFunction([=]{ return pleaseDumpNSSpeeds(fd); }); } catch(std::exception& e) { @@ -281,7 +281,7 @@ static string doDumpCache(T begin, T end) return "Error opening dump file for writing: "+stringerror()+"\n"; uint64_t total = 0; try { - total = s_RC->doDump(fd) + broadcastAccFunction(boost::bind(pleaseDump, fd)); + total = s_RC->doDump(fd) + broadcastAccFunction([=]{ return pleaseDump(fd); }); } catch(...){} @@ -303,7 +303,7 @@ static string doDumpEDNSStatus(T begin, T end) return "Error opening dump file for writing: "+stringerror()+"\n"; uint64_t total = 0; try { - total = broadcastAccFunction(boost::bind(pleaseDumpEDNSMap, fd)); + total = broadcastAccFunction([=]{ return pleaseDumpEDNSMap(fd); }); } catch(...){} @@ -364,7 +364,7 @@ static string doDumpThrottleMap(T begin, T end) return "Error opening dump file for writing: "+stringerror()+"\n"; uint64_t total = 0; try { - total = broadcastAccFunction(boost::bind(pleaseDumpThrottleMap, fd)); + total = broadcastAccFunction([=]{ return pleaseDumpThrottleMap(fd); }); } catch(...){} @@ -386,7 +386,7 @@ static string doDumpFailedServers(T begin, T end) return "Error opening dump file for writing: "+stringerror()+"\n"; uint64_t total = 0; try { - total = broadcastAccFunction(boost::bind(pleaseDumpFailedServers, fd)); + total = broadcastAccFunction([=]{ return pleaseDumpFailedServers(fd); }); } catch(...){} @@ -435,9 +435,9 @@ static string doWipeCache(T begin, T end, uint16_t qtype) int count=0, pcount=0, countNeg=0; for (auto wipe : toWipe) { - count+= broadcastAccFunction(boost::bind(pleaseWipeCache, wipe.first, wipe.second, qtype)); - pcount+= broadcastAccFunction(boost::bind(pleaseWipePacketCache, wipe.first, wipe.second, qtype)); - countNeg+=broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, wipe.first, wipe.second)); + count+= broadcastAccFunction([=]{ return pleaseWipeCache(wipe.first, wipe.second, qtype);}); + pcount+= broadcastAccFunction([=]{ return pleaseWipePacketCache(wipe.first, wipe.second, qtype);}); + countNeg+=broadcastAccFunction([=]{ return pleaseWipeAndCountNegCache(wipe.first, wipe.second);}); } return "wiped "+std::to_string(count)+" records, "+std::to_string(countNeg)+" negative records, "+std::to_string(pcount)+" packets\n"; @@ -538,9 +538,9 @@ static string doAddNTA(T begin, T end) g_luaconfs.modify([who, why](LuaConfigItems& lci) { lci.negAnchors[who] = why; }); - broadcastAccFunction(boost::bind(pleaseWipeCache, who, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, who, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, who, true)); + broadcastAccFunction([=]{return pleaseWipeCache(who, true, 0xffff);}); + broadcastAccFunction([=]{return pleaseWipePacketCache(who, true, 0xffff);}); + broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(who, true);}); return "Added Negative Trust Anchor for " + who.toLogString() + " with reason '" + why + "'\n"; } @@ -586,9 +586,9 @@ static string doClearNTA(T begin, T end) g_luaconfs.modify([entry](LuaConfigItems& lci) { lci.negAnchors.erase(entry); }); - broadcastAccFunction(boost::bind(pleaseWipeCache, entry, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, entry, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, entry, true)); + broadcastAccFunction([=]{return pleaseWipeCache(entry, true, 0xffff);}); + broadcastAccFunction([=]{return pleaseWipePacketCache(entry, true, 0xffff);}); + broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(entry, true);}); if (!first) { first = false; removed += ","; @@ -643,9 +643,9 @@ static string doAddTA(T begin, T end) auto ds=std::dynamic_pointer_cast(DSRecordContent::make(what)); lci.dsAnchors[who].insert(*ds); }); - broadcastAccFunction(boost::bind(pleaseWipeCache, who, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, who, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, who, true)); + broadcastAccFunction([=]{return pleaseWipeCache(who, true, 0xffff);}); + broadcastAccFunction([=]{return pleaseWipePacketCache(who, true, 0xffff);}); + broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(who, true);}); g_log<(boost::bind(pleaseWipeCache, entry, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, entry, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, entry, true)); + broadcastAccFunction([=]{return pleaseWipeCache(entry, true, 0xffff);}); + broadcastAccFunction([=]{return pleaseWipePacketCache(entry, true, 0xffff);}); + broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(entry, true);}); if (!first) { first = false; removed += ","; @@ -1112,13 +1112,13 @@ void registerAllStats() addGetStat("ecs-queries", &SyncRes::s_ecsqueries); addGetStat("ecs-responses", &SyncRes::s_ecsresponses); addGetStat("chain-resends", &g_stats.chainResends); - addGetStat("tcp-clients", boost::bind(TCPConnection::getCurrentConnections)); + addGetStat("tcp-clients", []{return TCPConnection::getCurrentConnections();}); #ifdef __linux__ - addGetStat("udp-recvbuf-errors", boost::bind(udpErrorStats, "udp-recvbuf-errors")); - addGetStat("udp-sndbuf-errors", boost::bind(udpErrorStats, "udp-sndbuf-errors")); - addGetStat("udp-noport-errors", boost::bind(udpErrorStats, "udp-noport-errors")); - addGetStat("udp-in-errors", boost::bind(udpErrorStats, "udp-in-errors")); + addGetStat("udp-recvbuf-errors", []{return udpErrorStats("udp-recvbuf-errors");}); + addGetStat("udp-sndbuf-errors", []{return udpErrorStats("udp-sndbuf-errors");}); + addGetStat("udp-noport-errors", []{return udpErrorStats("udp-noport-errors");}); + addGetStat("udp-in-errors", []{return udpErrorStats("udp-in-errors");}); #endif addGetStat("edns-ping-matches", &g_stats.ednsPingMatches); diff --git a/pdns/reczones.cc b/pdns/reczones.cc index 5b65d12167..019724596c 100644 --- a/pdns/reczones.cc +++ b/pdns/reczones.cc @@ -333,12 +333,12 @@ string reloadAuthAndForwards() } for(const auto& i : oldAndNewDomains) { - broadcastAccFunction(boost::bind(pleaseWipeCache, i, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, i, true, 0xffff)); - broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, i, true)); + broadcastAccFunction([&]{return pleaseWipeCache(i, true, 0xffff);}); + broadcastAccFunction([&]{return pleaseWipePacketCache(i, true, 0xffff);}); + broadcastAccFunction([&]{return pleaseWipeAndCountNegCache(i, true);}); } - broadcastFunction(boost::bind(pleaseUseNewSDomainsMap, newDomainMap)); + broadcastFunction([=]{return pleaseUseNewSDomainsMap(newDomainMap);}); return "ok\n"; } catch(std::exception& e) { diff --git a/pdns/webserver.cc b/pdns/webserver.cc index b47cc6d7e0..ca10668787 100644 --- a/pdns/webserver.cc +++ b/pdns/webserver.cc @@ -107,7 +107,7 @@ static void bareHandlerWrapper(WebServer::HandlerFunction handler, YaHTTP::Reque void WebServer::registerBareHandler(const string& url, HandlerFunction handler) { - YaHTTP::THandlerFunction f = std::bind(&bareHandlerWrapper, handler, std::placeholders::_1, std::placeholders::_2); + YaHTTP::THandlerFunction f = [=](YaHTTP::Request* req, YaHTTP::Response* resp){return bareHandlerWrapper(handler, req, resp);}; YaHTTP::Router::Any(url, f); } diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index a074460c2f..7ed832bd17 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -382,9 +382,9 @@ static void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) { DNSName canon = apiNameToDNSName(req->getvars["domain"]); bool subtree = (req->getvars.count("subtree") > 0 && req->getvars["subtree"].compare("true") == 0); - int count = broadcastAccFunction(std::bind(pleaseWipeCache, canon, subtree, 0xffff)); - count += broadcastAccFunction(std::bind(pleaseWipePacketCache, canon, subtree, 0xffff)); - count += broadcastAccFunction(std::bind(pleaseWipeAndCountNegCache, canon, subtree)); + int count = broadcastAccFunction([=]{return pleaseWipeCache(canon, subtree, 0xffff);}); + count += broadcastAccFunction([=]{return pleaseWipePacketCache(canon, subtree, 0xffff);}); + count += broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(canon, subtree);}); resp->setBody(Json::object { { "count", count }, { "result", "Flushed cache." }