From f151293e8a87d192ed1e4f3c95d9782c602a2efb Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 3 Jul 2026 12:17:03 +0100 Subject: [PATCH] chore: Enable modernize-avoid-bind (#7711) --- .clang-tidy | 1 - include/xrpl/basics/TaggedCache.ipp | 5 +- include/xrpl/beast/unit_test/thread.h | 5 +- include/xrpl/net/AutoSocket.h | 9 +- include/xrpl/net/HTTPClientSSLContext.h | 6 +- include/xrpl/server/detail/BaseHTTPPeer.h | 74 +++++--------- include/xrpl/server/detail/BasePeer.h | 3 +- include/xrpl/server/detail/BaseWSPeer.h | 66 ++++++------- include/xrpl/server/detail/Door.h | 9 +- include/xrpl/server/detail/PlainHTTPPeer.h | 10 +- include/xrpl/server/detail/SSLHTTPPeer.h | 18 ++-- src/libxrpl/basics/ResolverAsio.cpp | 34 +++---- src/libxrpl/beast/insight/StatsDCollector.cpp | 63 +++++------- src/libxrpl/core/detail/JobQueue.cpp | 3 +- src/libxrpl/net/HTTPClient.cpp | 69 +++++++------ src/test/jtx/impl/WSClient.cpp | 13 +-- src/test/overlay/short_read_test.cpp | 99 +++++++++---------- src/test/resource/Logic_test.cpp | 8 +- src/test/rpc/AccountTx_test.cpp | 3 +- src/test/rpc/LedgerRequest_test.cpp | 3 +- src/test/rpc/RPCCall_test.cpp | 3 +- src/test/rpc/TransactionEntry_test.cpp | 3 +- src/test/rpc/Transaction_test.cpp | 6 +- src/test/shamap/FetchPack_test.cpp | 96 ++++++++---------- src/xrpld/app/ledger/detail/LedgerMaster.cpp | 2 +- src/xrpld/app/misc/NetworkOPs.cpp | 2 +- src/xrpld/app/misc/SHAMapStoreImp.cpp | 8 +- src/xrpld/app/misc/detail/WorkBase.h | 38 +++---- src/xrpld/app/misc/detail/WorkFile.h | 6 +- src/xrpld/app/misc/detail/WorkSSL.cpp | 3 +- .../app/rdb/backend/detail/SQLiteDatabase.cpp | 20 ++-- src/xrpld/overlay/detail/ConnectAttempt.cpp | 20 ++-- src/xrpld/overlay/detail/OverlayImpl.cpp | 10 +- src/xrpld/overlay/detail/OverlayImpl.h | 2 +- src/xrpld/overlay/detail/PeerImp.cpp | 28 +++--- src/xrpld/peerfinder/detail/Checker.h | 3 +- src/xrpld/peerfinder/detail/Logic.h | 10 +- .../peerfinder/detail/PeerfinderManager.cpp | 3 +- src/xrpld/rpc/detail/Pathfinder.cpp | 9 +- src/xrpld/rpc/detail/RPCCall.cpp | 28 +++--- 40 files changed, 356 insertions(+), 445 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 6a24cbc8d3..c5f638b395 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -64,7 +64,6 @@ Checks: "-*, -misc-use-internal-linkage, modernize-*, - -modernize-avoid-bind, -modernize-avoid-c-arrays, -modernize-avoid-c-style-cast, -modernize-avoid-setjmp-longjmp, diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index ffcd533216..ca50bb64b7 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -57,7 +57,10 @@ inline TaggedCache< beast::insight::Collector::ptr const& collector) : journal_(journal) , clock_(clock) - , stats_(name, std::bind(&TaggedCache::collectMetrics, this), collector) + , stats_( + name, + [this] { collectMetrics(); }, + collector) , name_(name) , targetSize_(size) , targetAge_(expiration) diff --git a/include/xrpl/beast/unit_test/thread.h b/include/xrpl/beast/unit_test/thread.h index 0de039cb89..91d8cf3cab 100644 --- a/include/xrpl/beast/unit_test/thread.h +++ b/include/xrpl/beast/unit_test/thread.h @@ -45,7 +45,10 @@ public: template explicit Thread(Suite& s, F&& f, Args&&... args) : s_(&s) { - std::function b = std::bind(std::forward(f), std::forward(args)...); + std::function b = [f = std::forward(f), + ... args = std::forward(args)]() mutable { + std::invoke(f, args...); + }; t_ = std::thread(&Thread::run, this, std::move(b)); } diff --git a/include/xrpl/net/AutoSocket.h b/include/xrpl/net/AutoSocket.h index 72eaed7439..b98885959d 100644 --- a/include/xrpl/net/AutoSocket.h +++ b/include/xrpl/net/AutoSocket.h @@ -120,12 +120,9 @@ public: socket_->next_layer().async_receive( boost::asio::buffer(buffer_), boost::asio::socket_base::message_peek, - std::bind( - &AutoSocket::handleAutodetect, - this, - cbFunc, - std::placeholders::_1, - std::placeholders::_2)); + [this, cbFunc](error_code const& ec, size_t bytesTransferred) { + handleAutodetect(cbFunc, ec, bytesTransferred); + }); } } diff --git a/include/xrpl/net/HTTPClientSSLContext.h b/include/xrpl/net/HTTPClientSSLContext.h index 4192455ec9..2b26d7e404 100644 --- a/include/xrpl/net/HTTPClientSSLContext.h +++ b/include/xrpl/net/HTTPClientSSLContext.h @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -127,8 +126,9 @@ public: if (!ec) { strm.set_verify_callback( - std::bind( - &rfc6125Verify, host, std::placeholders::_1, std::placeholders::_2, j_), + [host, j = j_](bool preverified, boost::asio::ssl::verify_context& ctx) { + return rfc6125Verify(host, preverified, ctx, j); + }, ec); } } diff --git a/include/xrpl/server/detail/BaseHTTPPeer.h b/include/xrpl/server/detail/BaseHTTPPeer.h index f096d3c5a9..7b35dbd4be 100644 --- a/include/xrpl/server/detail/BaseHTTPPeer.h +++ b/include/xrpl/server/detail/BaseHTTPPeer.h @@ -223,10 +223,7 @@ BaseHTTPPeer::close() { if (!strand_.running_in_this_thread()) { - return post( - strand_, - std::bind( - (void (BaseHTTPPeer::*)(void))&BaseHTTPPeer::close, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->close(); }); } boost::beast::get_lowest_layer(impl().stream_).close(); } @@ -322,22 +319,18 @@ BaseHTTPPeer::onWrite(error_code const& ec, std::size_t bytesTran v, bind_executor( strand_, - std::bind( - &BaseHTTPPeer::onWrite, - impl().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = impl().shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onWrite(ec, bytesTransferred); + })); } if (!complete_) return; if (graceful_) return doClose(); - util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doRead, - impl().shared_from_this(), - std::placeholders::_1)); + util::spawn(strand_, [self = impl().shared_from_this()](yield_context doYield) { + self->doRead(doYield); + }); } template @@ -351,14 +344,9 @@ BaseHTTPPeer::doWriter( { auto const p = impl().shared_from_this(); resume = std::function([this, p, writer, keepAlive]() { - util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doWriter, - p, - writer, - keepAlive, - std::placeholders::_1)); + util::spawn(strand_, [p, writer, keepAlive](yield_context doYield) { + p->doWriter(writer, keepAlive, doYield); + }); }); } @@ -379,12 +367,9 @@ BaseHTTPPeer::doWriter( if (!keepAlive) return doClose(); - util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doRead, - impl().shared_from_this(), - std::placeholders::_1)); + util::spawn(strand_, [self = impl().shared_from_this()](yield_context doYield) { + self->doRead(doYield); + }); } //------------------------------------------------------------------------------ @@ -405,8 +390,7 @@ BaseHTTPPeer::write(void const* buf, std::size_t bytes) if (!strand_.running_in_this_thread()) { return post( - strand_, - std::bind(&BaseHTTPPeer::onWrite, impl().shared_from_this(), error_code{}, 0)); + strand_, [self = impl().shared_from_this()] { self->onWrite(error_code{}, 0); }); } return onWrite(error_code{}, 0); } @@ -417,13 +401,9 @@ void BaseHTTPPeer::write(std::shared_ptr const& writer, bool keepAlive) { util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doWriter, - impl().shared_from_this(), - writer, - keepAlive, - std::placeholders::_1)); + strand_, [self = impl().shared_from_this(), writer, keepAlive](yield_context doYield) { + self->doWriter(writer, keepAlive, doYield); + }); } // DEPRECATED @@ -443,8 +423,7 @@ BaseHTTPPeer::complete() { if (!strand_.running_in_this_thread()) { - return post( - strand_, std::bind(&BaseHTTPPeer::complete, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->complete(); }); } message_ = {}; @@ -457,12 +436,9 @@ BaseHTTPPeer::complete() } // keep-alive - util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doRead, - impl().shared_from_this(), - std::placeholders::_1)); + util::spawn(strand_, [self = impl().shared_from_this()](yield_context doYield) { + self->doRead(doYield); + }); } // DEPRECATED @@ -474,11 +450,7 @@ BaseHTTPPeer::close(bool graceful) if (!strand_.running_in_this_thread()) { return post( - strand_, - std::bind( - (void (BaseHTTPPeer::*)(bool))&BaseHTTPPeer::close, - impl().shared_from_this(), - graceful)); + strand_, [self = impl().shared_from_this(), graceful] { self->close(graceful); }); } complete_ = true; diff --git a/include/xrpl/server/detail/BasePeer.h b/include/xrpl/server/detail/BasePeer.h index 5301a2f018..84aa1e0da9 100644 --- a/include/xrpl/server/detail/BasePeer.h +++ b/include/xrpl/server/detail/BasePeer.h @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -84,7 +83,7 @@ void BasePeer::close() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BasePeer::close, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->close(); }); error_code ec; xrpl::getLowestLayer(impl().ws_).socket().close(ec); } diff --git a/include/xrpl/server/detail/BaseWSPeer.h b/include/xrpl/server/detail/BaseWSPeer.h index 1b6a9faca3..d557140bd4 100644 --- a/include/xrpl/server/detail/BaseWSPeer.h +++ b/include/xrpl/server/detail/BaseWSPeer.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -180,12 +181,13 @@ void BaseWSPeer::run() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::run, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->run(); }); impl().ws_.set_option(port().pmdOptions); // Must manage the control callback memory outside of the `control_callback` // function - controlCallback_ = - std::bind(&BaseWSPeer::onPingPong, this, std::placeholders::_1, std::placeholders::_2); + controlCallback_ = [this]( + boost::beast::websocket::frame_type kind, + boost::beast::string_view payload) { onPingPong(kind, payload); }; impl().ws_.control_callback(controlCallback_); startTimer(); closeOnTimer_ = true; @@ -193,11 +195,9 @@ BaseWSPeer::run() res.set(boost::beast::http::field::server, BuildInfo::getFullVersionString()); })); impl().ws_.async_accept( - request_, - bind_executor( - strand_, - std::bind( - &BaseWSPeer::onWsHandshake, impl().shared_from_this(), std::placeholders::_1))); + request_, bind_executor(strand_, [self = impl().shared_from_this()](error_code const& ec) { + self->onWsHandshake(ec); + })); } template @@ -205,7 +205,10 @@ void BaseWSPeer::send(std::shared_ptr w) { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::send, impl().shared_from_this(), std::move(w))); + { + return post( + strand_, [self = impl().shared_from_this(), w = std::move(w)] { self->send(w); }); + } if (doClose_) return; if (wq_.size() > port().wsQueueLimit) @@ -258,7 +261,7 @@ void BaseWSPeer::complete() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::complete, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->complete(); }); doRead(); } @@ -277,7 +280,7 @@ void BaseWSPeer::doWrite() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::doWrite, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->doWrite(); }); onWrite({}); } @@ -288,8 +291,7 @@ BaseWSPeer::onWrite(error_code const& ec) if (ec) return fail(ec, "write"); auto& w = *wq_.front(); - auto const result = - w.prepare(65536, std::bind(&BaseWSPeer::doWrite, impl().shared_from_this())); + auto const result = w.prepare(65536, [self = impl().shared_from_this()] { self->doWrite(); }); if (boost::indeterminate(result.first)) return; startTimer(); @@ -299,8 +301,9 @@ BaseWSPeer::onWrite(error_code const& ec) static_cast(result.first), result.second, bind_executor( - strand_, - std::bind(&BaseWSPeer::onWrite, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onWrite(ec); + })); } else { @@ -308,9 +311,9 @@ BaseWSPeer::onWrite(error_code const& ec) static_cast(result.first), result.second, bind_executor( - strand_, - std::bind( - &BaseWSPeer::onWriteFin, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onWriteFin(ec); + })); } } @@ -324,10 +327,9 @@ BaseWSPeer::onWriteFin(error_code const& ec) if (doClose_) { impl().ws_.async_close( - cr_, - bind_executor( - strand_, - std::bind(&BaseWSPeer::onClose, impl().shared_from_this(), std::placeholders::_1))); + cr_, bind_executor(strand_, [self = impl().shared_from_this()](error_code const& ec) { + self->onClose(ec); + })); } else if (!wq_.empty()) { @@ -340,12 +342,13 @@ void BaseWSPeer::doRead() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::doRead, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->doRead(); }); impl().ws_.async_read( rb_, bind_executor( - strand_, - std::bind(&BaseWSPeer::onRead, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onRead(ec); + })); } template @@ -389,11 +392,7 @@ BaseWSPeer::startTimer() } timer_.async_wait(bind_executor( - strand_, - std::bind( - &BaseWSPeer::onTimer, - impl().shared_from_this(), - std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec) { self->onTimer(ec); })); } // Convenience for discarding the error code @@ -461,10 +460,9 @@ BaseWSPeer::onTimer(error_code ec) beast::rngfill(payload_.begin(), payload_.size(), cryptoPrng()); impl().ws_.async_ping( payload_, - bind_executor( - strand_, - std::bind( - &BaseWSPeer::onPing, impl().shared_from_this(), std::placeholders::_1))); + bind_executor(strand_, [self = impl().shared_from_this()](error_code const& ec) { + self->onPing(ec); + })); JLOG(this->j_.trace()) << "sent ping"; return; } diff --git a/include/xrpl/server/detail/Door.h b/include/xrpl/server/detail/Door.h index 09b0adc5f2..d2d7a7baf4 100644 --- a/include/xrpl/server/detail/Door.h +++ b/include/xrpl/server/detail/Door.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -182,7 +181,7 @@ void Door::Detector::run() { util::spawn( - strand_, std::bind(&Detector::doDetect, this->shared_from_this(), std::placeholders::_1)); + strand_, [self = this->shared_from_this()](yield_context yield) { self->doDetect(yield); }); } template @@ -297,8 +296,7 @@ void Door::run() { util::spawn( - strand_, - std::bind(&Door::doAccept, this->shared_from_this(), std::placeholders::_1)); + strand_, [self = this->shared_from_this()](yield_context yield) { self->doAccept(yield); }); } template @@ -307,8 +305,7 @@ Door::close() { if (!strand_.running_in_this_thread()) { - return boost::asio::post( - strand_, std::bind(&Door::close, this->shared_from_this())); + return boost::asio::post(strand_, [self = this->shared_from_this()] { self->close(); }); } backoffTimer_.cancel(); error_code ec; diff --git a/include/xrpl/server/detail/PlainHTTPPeer.h b/include/xrpl/server/detail/PlainHTTPPeer.h index b89272fe9e..688fbbd425 100644 --- a/include/xrpl/server/detail/PlainHTTPPeer.h +++ b/include/xrpl/server/detail/PlainHTTPPeer.h @@ -9,7 +9,6 @@ #include -#include #include #include @@ -89,7 +88,9 @@ PlainHTTPPeer::run() { if (!this->handler_.onAccept(this->session(), this->remoteAddress_)) { - util::spawn(this->strand_, std::bind(&PlainHTTPPeer::doClose, this->shared_from_this())); + util::spawn(this->strand_, [self = this->shared_from_this()](boost::asio::yield_context) { + self->doClose(); + }); return; } @@ -97,8 +98,9 @@ PlainHTTPPeer::run() return; util::spawn( - this->strand_, - std::bind(&PlainHTTPPeer::doRead, this->shared_from_this(), std::placeholders::_1)); + this->strand_, [self = this->shared_from_this()](boost::asio::yield_context doYield) { + self->doRead(doYield); + }); } template diff --git a/include/xrpl/server/detail/SSLHTTPPeer.h b/include/xrpl/server/detail/SSLHTTPPeer.h index ea2108b917..7fe21ed6b5 100644 --- a/include/xrpl/server/detail/SSLHTTPPeer.h +++ b/include/xrpl/server/detail/SSLHTTPPeer.h @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -99,14 +98,15 @@ SSLHTTPPeer::run() { if (!this->handler_.onAccept(this->session(), this->remoteAddress_)) { - util::spawn(this->strand_, std::bind(&SSLHTTPPeer::doClose, this->shared_from_this())); + util::spawn( + this->strand_, [self = this->shared_from_this()](yield_context) { self->doClose(); }); return; } if (!socket_.is_open()) return; - util::spawn( - this->strand_, - std::bind(&SSLHTTPPeer::doHandshake, this->shared_from_this(), std::placeholders::_1)); + util::spawn(this->strand_, [self = this->shared_from_this()](yield_context doYield) { + self->doHandshake(doYield); + }); } template @@ -142,9 +142,9 @@ SSLHTTPPeer::doHandshake(yield_context doYield) this->port().protocol.count("https") > 0; if (http) { - util::spawn( - this->strand_, - std::bind(&SSLHTTPPeer::doRead, this->shared_from_this(), std::placeholders::_1)); + util::spawn(this->strand_, [self = this->shared_from_this()](yield_context doYield) { + self->doRead(doYield); + }); return; } // `this` will be destroyed @@ -172,7 +172,7 @@ SSLHTTPPeer::doClose() this->startTimer(); stream_.async_shutdown(bind_executor( this->strand_, - std::bind(&SSLHTTPPeer::onShutdown, this->shared_from_this(), std::placeholders::_1))); + [self = this->shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); } template diff --git a/src/libxrpl/basics/ResolverAsio.cpp b/src/libxrpl/basics/ResolverAsio.cpp index ddf006b681..7e1b56f87a 100644 --- a/src/libxrpl/basics/ResolverAsio.cpp +++ b/src/libxrpl/basics/ResolverAsio.cpp @@ -192,7 +192,7 @@ public: boost::asio::dispatch( ioContext, boost::asio::bind_executor( - strand, std::bind(&ResolverAsioImpl::doStop, this, CompletionCounter(this)))); + strand, [this, counter = CompletionCounter(this)] { doStop(counter); })); JLOG(journal.debug()) << "Queued a stop request"; } @@ -221,9 +221,9 @@ public: boost::asio::dispatch( ioContext, boost::asio::bind_executor( - strand, - std::bind( - &ResolverAsioImpl::doResolve, this, names, handler, CompletionCounter(this)))); + strand, [this, names, handler, counter = CompletionCounter(this)] { + doResolve(names, handler, counter); + })); } //------------------------------------------------------------------------- @@ -272,7 +272,7 @@ public: boost::asio::post( ioContext, boost::asio::bind_executor( - strand, std::bind(&ResolverAsioImpl::doWork, this, CompletionCounter(this)))); + strand, [this, counter = CompletionCounter(this)] { doWork(counter); })); } static HostAndPort @@ -291,8 +291,10 @@ public: // a port separator // Attempt to find the first and last non-whitespace - auto const findWhitespace = - std::bind(&std::isspace, std::placeholders::_1, std::locale()); + std::locale const loc; + auto const findWhitespace = [&loc](std::string::value_type c) { + return std::isspace(c, loc); + }; auto hostFirst = std::ranges::find_if_not(str, findWhitespace); @@ -348,7 +350,7 @@ public: boost::asio::post( ioContext, boost::asio::bind_executor( - strand, std::bind(&ResolverAsioImpl::doWork, this, CompletionCounter(this)))); + strand, [this, counter = CompletionCounter(this)] { doWork(counter); })); return; } @@ -356,14 +358,11 @@ public: resolver.async_resolve( host, port, - std::bind( - &ResolverAsioImpl::doFinish, - this, - name, - std::placeholders::_1, - handler, - std::placeholders::_2, - CompletionCounter(this))); + [this, name, handler, counter = CompletionCounter(this)]( + boost::system::error_code const& ec, + boost::asio::ip::tcp::resolver::results_type results) { + doFinish(name, ec, handler, results, counter); + }); } void @@ -383,8 +382,7 @@ public: boost::asio::post( ioContext, boost::asio::bind_executor( - strand, - std::bind(&ResolverAsioImpl::doWork, this, CompletionCounter(this)))); + strand, [this, counter = CompletionCounter(this)] { doWork(counter); })); } } } diff --git a/src/libxrpl/beast/insight/StatsDCollector.cpp b/src/libxrpl/beast/insight/StatsDCollector.cpp index 1da5315de1..3cff5d93b5 100644 --- a/src/libxrpl/beast/insight/StatsDCollector.cpp +++ b/src/libxrpl/beast/insight/StatsDCollector.cpp @@ -325,9 +325,9 @@ public: postBuffer(std::string&& buffer) { boost::asio::dispatch( - ioContext_, - boost::asio::bind_executor( - strand_, std::bind(&StatsDCollectorImp::doPostBuffer, this, std::move(buffer)))); + ioContext_, boost::asio::bind_executor(strand_, [this, buffer = std::move(buffer)] { + doPostBuffer(buffer); + })); } // The keepAlive parameter makes sure the buffers sent to @@ -392,12 +392,10 @@ public: log(buffers); socket_.async_send( buffers, - std::bind( - &StatsDCollectorImp::onSend, - this, - keepAlive, - std::placeholders::_1, - std::placeholders::_2)); + [this, keepAlive]( + boost::system::error_code const& ec, std::size_t bytesTransferred) { + onSend(keepAlive, ec, bytesTransferred); + }); buffers.clear(); size = 0; } @@ -411,12 +409,10 @@ public: log(buffers); socket_.async_send( buffers, - std::bind( - &StatsDCollectorImp::onSend, - this, - keepAlive, - std::placeholders::_1, - std::placeholders::_2)); + [this, keepAlive]( + boost::system::error_code const& ec, std::size_t bytesTransferred) { + onSend(keepAlive, ec, bytesTransferred); + }); } } @@ -425,7 +421,7 @@ public: { using namespace std::chrono_literals; timer_.expires_after(1s); - timer_.async_wait(std::bind(&StatsDCollectorImp::onTimer, this, std::placeholders::_1)); + timer_.async_wait([this](boost::system::error_code const& ec) { onTimer(ec); }); } void @@ -513,10 +509,9 @@ StatsDCounterImpl::increment(CounterImpl::value_type amount) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDCounterImpl::doIncrement, - std::static_pointer_cast(shared_from_this()), - amount)); + [self = std::static_pointer_cast(shared_from_this()), amount] { + self->doIncrement(amount); + }); } void @@ -558,10 +553,9 @@ StatsDEventImpl::notify(EventImpl::value_type const& value) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDEventImpl::doNotify, - std::static_pointer_cast(shared_from_this()), - value)); + [self = std::static_pointer_cast(shared_from_this()), value] { + self->doNotify(value); + }); } void @@ -591,10 +585,9 @@ StatsDGaugeImpl::set(GaugeImpl::value_type value) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDGaugeImpl::doSet, - std::static_pointer_cast(shared_from_this()), - value)); + [self = std::static_pointer_cast(shared_from_this()), value] { + self->doSet(value); + }); } void @@ -602,10 +595,9 @@ StatsDGaugeImpl::increment(GaugeImpl::difference_type amount) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDGaugeImpl::doIncrement, - std::static_pointer_cast(shared_from_this()), - amount)); + [self = std::static_pointer_cast(shared_from_this()), amount] { + self->doIncrement(amount); + }); } void @@ -678,10 +670,9 @@ StatsDMeterImpl::increment(MeterImpl::value_type amount) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDMeterImpl::doIncrement, - std::static_pointer_cast(shared_from_this()), - amount)); + [self = std::static_pointer_cast(shared_from_this()), amount] { + self->doIncrement(amount); + }); } void diff --git a/src/libxrpl/core/detail/JobQueue.cpp b/src/libxrpl/core/detail/JobQueue.cpp index f773270af3..8f95a8a5fa 100644 --- a/src/libxrpl/core/detail/JobQueue.cpp +++ b/src/libxrpl/core/detail/JobQueue.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -36,7 +35,7 @@ JobQueue::JobQueue( { JLOG(journal_.info()) << "Using " << threadCount << " threads"; - hook_ = collector_->makeHook(std::bind(&JobQueue::collect, this)); + hook_ = collector_->makeHook([this] { collect(); }); jobCount_ = collector_->makeGauge("job_count"); { diff --git a/src/libxrpl/net/HTTPClient.cpp b/src/libxrpl/net/HTTPClient.cpp index 4b9cc9d6e6..7294633964 100644 --- a/src/libxrpl/net/HTTPClient.cpp +++ b/src/libxrpl/net/HTTPClient.cpp @@ -134,12 +134,10 @@ public: request( bSSL, deqSites, - std::bind( - &HTTPClientImp::makeGet, - shared_from_this(), - strPath, - std::placeholders::_1, - std::placeholders::_2), + [self = shared_from_this(), strPath]( + boost::asio::streambuf& sb, std::string const& strHost) { + self->makeGet(strPath, sb, strHost); + }, timeout, complete); } @@ -166,9 +164,9 @@ public: shutdown_ = e.code(); JLOG(j_.trace()) << "expires_after: " << shutdown_.message(); - deadline_.async_wait( - std::bind( - &HTTPClientImp::handleDeadline, shared_from_this(), std::placeholders::_1)); + deadline_.async_wait([self = shared_from_this()](boost::system::error_code const& ec) { + self->handleDeadline(ec); + }); } if (!shutdown_) @@ -179,11 +177,11 @@ public: query_->host, query_->port, query_->flags, - std::bind( - &HTTPClientImp::handleResolve, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, + boost::asio::ip::tcp::resolver::results_type results) { + self->handleResolve(ecResult, results); + }); } if (shutdown_) @@ -220,9 +218,9 @@ public: resolver_.cancel(); // Stop the transaction. - socket_.asyncShutdown( - std::bind( - &HTTPClientImp::handleShutdown, shared_from_this(), std::placeholders::_1)); + socket_.asyncShutdown([self = shared_from_this()](boost::system::error_code const& ec) { + self->handleShutdown(ec); + }); } } @@ -262,8 +260,9 @@ public: boost::asio::async_connect( socket_.lowestLayer(), result, - std::bind( - &HTTPClientImp::handleConnect, shared_from_this(), std::placeholders::_1)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, + boost::asio::ip::tcp::endpoint const&) { self->handleConnect(ecResult); }); } } @@ -301,8 +300,9 @@ public: { socket_.asyncHandshake( AutoSocket::ssl_socket::client, - std::bind( - &HTTPClientImp::handleRequest, shared_from_this(), std::placeholders::_1)); + [self = shared_from_this()](boost::system::error_code const& ec) { + self->handleRequest(ec); + }); } else { @@ -330,11 +330,10 @@ public: socket_.asyncWrite( request_, - std::bind( - &HTTPClientImp::handleWrite, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, std::size_t bytesTransferred) { + self->handleWrite(ecResult, bytesTransferred); + }); } } @@ -357,11 +356,10 @@ public: socket_.asyncReadUntil( header_, "\r\n\r\n", - std::bind( - &HTTPClientImp::handleHeader, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, std::size_t bytesTransferred) { + self->handleHeader(ecResult, bytesTransferred); + }); } } @@ -424,11 +422,10 @@ public: socket_.asyncRead( response_.prepare(responseSize - body_.size()), boost::asio::transfer_all(), - std::bind( - &HTTPClientImp::handleData, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, std::size_t bytesTransferred) { + self->handleData(ecResult, bytesTransferred); + }); } } diff --git a/src/test/jtx/impl/WSClient.cpp b/src/test/jtx/impl/WSClient.cpp index c00a88f270..ca322415fb 100644 --- a/src/test/jtx/impl/WSClient.cpp +++ b/src/test/jtx/impl/WSClient.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -172,9 +173,9 @@ public: })); ws_.handshake(ep.address().to_string() + ":" + std::to_string(ep.port()), "/"); ws_.async_read( - rb_, - boost::asio::bind_executor( - strand_, std::bind(&WSClientImpl::onReadMsg, this, std::placeholders::_1))); + rb_, boost::asio::bind_executor(strand_, [this](error_code const& ec, std::size_t) { + onReadMsg(ec); + })); } catch (std::exception&) { @@ -310,9 +311,9 @@ private: cv_.notify_all(); } ws_.async_read( - rb_, - boost::asio::bind_executor( - strand_, std::bind(&WSClientImpl::onReadMsg, this, std::placeholders::_1))); + rb_, boost::asio::bind_executor(strand_, [this](error_code const& ec, std::size_t) { + onReadMsg(ec); + })); } // Called when the read op terminates diff --git a/src/test/overlay/short_read_test.cpp b/src/test/overlay/short_read_test.cpp index 9af632d65c..f235008d89 100644 --- a/src/test/overlay/short_read_test.cpp +++ b/src/test/overlay/short_read_test.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -199,7 +198,7 @@ private: { if (!strand.running_in_this_thread()) { - post(strand, std::bind(&Acceptor::close, shared_from_this())); + post(strand, [self = shared_from_this()] { self->close(); }); return; } acceptor.close(); @@ -210,9 +209,9 @@ private: { acceptor.async_accept( socket, - bind_executor( - strand, - std::bind(&Acceptor::onAccept, shared_from_this(), std::placeholders::_1))); + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onAccept(ec); + })); } void @@ -239,9 +238,9 @@ private: p->run(); acceptor.async_accept( socket, - bind_executor( - strand, - std::bind(&Acceptor::onAccept, shared_from_this(), std::placeholders::_1))); + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onAccept(ec); + })); } }; @@ -271,7 +270,7 @@ private: { if (!strand.running_in_this_thread()) { - post(strand, std::bind(&Connection::close, shared_from_this())); + post(strand, [self = shared_from_this()] { self->close(); }); return; } if (socket.is_open()) @@ -287,13 +286,12 @@ private: timer.expires_after(std::chrono::seconds(3)); timer.async_wait(bind_executor( strand, - std::bind(&Connection::onTimer, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); stream.async_handshake( stream_type::server, - bind_executor( - strand, - std::bind( - &Connection::onHandshake, shared_from_this(), std::placeholders::_1))); + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onHandshake(ec); + })); } void @@ -337,11 +335,10 @@ private: "\n", bind_executor( strand, - std::bind( - &Connection::onRead, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onRead(ec, bytesTransferred); + })); #else close(); #endif @@ -353,10 +350,10 @@ private: if (ec == boost::asio::error::eof) { server.test_.log << "[server] read: EOF" << std::endl; - stream.async_shutdown(bind_executor( - strand, - std::bind( - &Connection::onShutdown, shared_from_this(), std::placeholders::_1))); + stream.async_shutdown( + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onShutdown(ec); + })); return; } if (ec) @@ -373,11 +370,10 @@ private: buf.data(), bind_executor( strand, - std::bind( - &Connection::onWrite, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onWrite(ec, bytesTransferred); + })); } void @@ -391,7 +387,7 @@ private: } stream.async_shutdown(bind_executor( strand, - std::bind(&Connection::onShutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); } void @@ -463,7 +459,7 @@ private: { if (!strand.running_in_this_thread()) { - post(strand, std::bind(&Connection::close, shared_from_this())); + post(strand, [self = shared_from_this()] { self->close(); }); return; } if (socket.is_open()) @@ -479,13 +475,11 @@ private: timer.expires_after(std::chrono::seconds(3)); timer.async_wait(bind_executor( strand, - std::bind(&Connection::onTimer, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); socket.async_connect( - ep, - bind_executor( - strand, - std::bind( - &Connection::onConnect, shared_from_this(), std::placeholders::_1))); + ep, bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onConnect(ec); + })); } void @@ -524,10 +518,9 @@ private: } stream.async_handshake( stream_type::client, - bind_executor( - strand, - std::bind( - &Connection::onHandshake, shared_from_this(), std::placeholders::_1))); + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onHandshake(ec); + })); } void @@ -546,16 +539,14 @@ private: buf.data(), bind_executor( strand, - std::bind( - &Connection::onWrite, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onWrite(ec, bytesTransferred); + })); #else stream_.async_shutdown(bind_executor( strand_, - std::bind( - &Connection::on_shutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->on_shutdown(ec); })); #endif } @@ -575,16 +566,14 @@ private: "\n", bind_executor( strand, - std::bind( - &Connection::onRead, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onRead(ec, bytesTransferred); + })); #else stream_.async_shutdown(bind_executor( strand_, - std::bind( - &Connection::on_shutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->on_shutdown(ec); })); #endif } @@ -599,7 +588,7 @@ private: buf.commit(bytesTransferred); stream.async_shutdown(bind_executor( strand, - std::bind(&Connection::onShutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); } void diff --git a/src/test/resource/Logic_test.cpp b/src/test/resource/Logic_test.cpp index de4575cb16..f6b4875356 100644 --- a/src/test/resource/Logic_test.cpp +++ b/src/test/resource/Logic_test.cpp @@ -89,9 +89,11 @@ public: Charge const fee(kDropThreshold + 1); beast::IP::Endpoint const addr(beast::IP::Endpoint::fromString("192.0.2.2")); - std::function const ep = limited - ? std::bind(&TestLogic::newInboundEndpoint, &logic, std::placeholders::_1) - : std::bind(&TestLogic::newUnlimitedEndpoint, &logic, std::placeholders::_1); + std::function const ep = + [&logic, limited](beast::IP::Endpoint const& address) { + return limited ? logic.newInboundEndpoint(address) + : logic.newUnlimitedEndpoint(address); + }; { Consumer c(ep(addr)); diff --git a/src/test/rpc/AccountTx_test.cpp b/src/test/rpc/AccountTx_test.cpp index bd7b07e936..ace8743e1e 100644 --- a/src/test/rpc/AccountTx_test.cpp +++ b/src/test/rpc/AccountTx_test.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -893,7 +892,7 @@ public: void run() override { - forAllApiVersions(std::bind_front(&AccountTx_test::testParameters, this)); + forAllApiVersions([this](unsigned apiVersion) { testParameters(apiVersion); }); testContents(); testAccountDelete(); testMPT(); diff --git a/src/test/rpc/LedgerRequest_test.cpp b/src/test/rpc/LedgerRequest_test.cpp index 4759256b96..93feee9497 100644 --- a/src/test/rpc/LedgerRequest_test.cpp +++ b/src/test/rpc/LedgerRequest_test.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -350,7 +349,7 @@ public: { testLedgerRequest(); testEvolution(); - forAllApiVersions(std::bind_front(&LedgerRequest_test::testBadInput, this)); + forAllApiVersions([this](unsigned apiVersion) { testBadInput(apiVersion); }); testMoreThan256Closed(); testNonAdmin(); } diff --git a/src/test/rpc/RPCCall_test.cpp b/src/test/rpc/RPCCall_test.cpp index cd3cd3cb41..4b5ab1f230 100644 --- a/src/test/rpc/RPCCall_test.cpp +++ b/src/test/rpc/RPCCall_test.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -5927,7 +5926,7 @@ public: void run() override { - forAllApiVersions(std::bind_front(&RPCCall_test::testRPCCall, this)); + forAllApiVersions([this](unsigned apiVersion) { testRPCCall(apiVersion); }); } }; diff --git a/src/test/rpc/TransactionEntry_test.cpp b/src/test/rpc/TransactionEntry_test.cpp index 8724e2974d..38a95e84f8 100644 --- a/src/test/rpc/TransactionEntry_test.cpp +++ b/src/test/rpc/TransactionEntry_test.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -353,7 +352,7 @@ public: run() override { testBadInput(); - forAllApiVersions(std::bind_front(&TransactionEntry_test::testRequest, this)); + forAllApiVersions([this](unsigned apiVersion) { testRequest(apiVersion); }); } }; diff --git a/src/test/rpc/Transaction_test.cpp b/src/test/rpc/Transaction_test.cpp index 8c50736b85..c3bf707ec4 100644 --- a/src/test/rpc/Transaction_test.cpp +++ b/src/test/rpc/Transaction_test.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -886,7 +885,7 @@ public: run() override { using namespace test::jtx; - forAllApiVersions(std::bind_front(&Transaction_test::testBinaryRequest, this)); + forAllApiVersions([this](unsigned apiVersion) { testBinaryRequest(apiVersion); }); FeatureBitset const all{testableAmendments()}; testWithFeats(all); @@ -899,7 +898,8 @@ public: testRangeCTIDRequest(features); testCTIDValidation(features); testRPCsForCTID(features); - forAllApiVersions(std::bind_front(&Transaction_test::testRequest, this, features)); + forAllApiVersions( + [this, features](unsigned apiVersion) { testRequest(features, apiVersion); }); } }; diff --git a/src/test/shamap/FetchPack_test.cpp b/src/test/shamap/FetchPack_test.cpp index bcc5129f01..f2e7578ee2 100644 --- a/src/test/shamap/FetchPack_test.cpp +++ b/src/test/shamap/FetchPack_test.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -26,7 +25,6 @@ #include #include #include -#include namespace xrpl::tests { @@ -40,15 +38,6 @@ public: using Table = SHAMap; using Item = SHAMapItem; - struct Handler - { - void - operator()(std::uint32_t refNum) const - { - Throw("missing node"); - } - }; - struct TestFilter : SHAMapSyncFilter { TestFilter(Map& map, beast::Journal journal) : map(map), journal(journal) @@ -93,7 +82,7 @@ public: static void addRandomItems(std::size_t n, Table& t, beast::xor_shift_engine& r) { - while ((n--) != 0u) + for (std::size_t i = 0; i < n; ++i) { auto const result(t.addItem(SHAMapNodeType::TnAccountState, makeRandomItemMember(r))); assert(result); @@ -111,56 +100,51 @@ public: void run() override { - using beast::Severity; + testFetchPack(); + } + + // Exercises a fetch-pack round trip: build a SHAMap, serialize every node + // into a pack keyed by node hash, then rebuild the map in a fresh SHAMap by + // sourcing every node from the pack through a SHAMapSyncFilter and comparing + // the result. This covers the filter-based reconstruction path (fetchRoot + + // getMissingNodes with a SHAMapSyncFilter), complementing SHAMapSync_test, + // which drives the getNodeFat/addKnownNode path. + void + testFetchPack() + { test::SuiteJournal journal("FetchPack_test", *this); + TestNodeFamily f(journal), f2(journal); + beast::xor_shift_engine r; - TestNodeFamily f(journal); - std::shared_ptr const t1(std::make_shared
(SHAMapType::FREE, f)); + // Build a source map. getHash() unshares the tree and computes every + // node hash; this must happen before serializing nodes below, otherwise + // inner nodes still carry stale cached hashes. + auto const source = std::make_shared
(SHAMapType::FREE, f); + addRandomItems(kTableItems + kTableItemsExtra, *source, r); + source->setImmutable(); + auto const rootHash = source->getHash(); - pass(); + // Turn the source into a fetch pack: node hash -> serialized node. + Map map; + source->visitNodes([this, &map](SHAMapTreeNode& node) { + Serializer s; + node.serializeWithPrefix(s); + onFetch(map, node.getHash(), s.getData()); + return true; + }); - // beast::Random r; - // add_random_items_ (tableItems, *t1, r); - // std::shared_ptr
t2 (t1->snapShot (true)); - // - // add_random_items_ (tableItemsExtra, *t1, r); - // add_random_items_ (tableItemsExtra, *t2, r); + // Rebuild the map in a fresh family, sourcing every node from the pack + // through the SHAMapSyncFilter. + auto const rebuilt = std::make_shared
(SHAMapType::FREE, rootHash.asUInt256(), f2); + TestFilter filter(map, journal); + rebuilt->setSynching(); + BEAST_EXPECT(rebuilt->fetchRoot(rootHash, &filter)); - // turn t1 into t2 - // Map map; - // t2->getFetchPack (t1.get(), true, 1000000, std::bind ( - // &FetchPack_test::on_fetch, this, std::ref (map), - // std::placeholders::_1, std::placeholders::_2)); - // t1->getFetchPack (nullptr, true, 1000000, std::bind ( - // &FetchPack_test::on_fetch, this, std::ref (map), - // std::placeholders::_1, std::placeholders::_2)); + // Everything should be in the pack, so no nodes should be missing. + BEAST_EXPECT(rebuilt->getMissingNodes(2048, &filter).empty()); + rebuilt->clearSynching(); - // try to rebuild t2 from the fetch pack - // std::shared_ptr
t3; - // try - // { - // TestFilter filter (map, beast::Journal()); - // - // t3 = std::make_shared
(SHAMapType::FREE, - // t2->getHash (), - // fullBelowCache); - // - // BEAST_EXPECT(t3->fetchRoot (t2->getHash (), &filter), - // "unable to get root"); - // - // // everything should be in the pack, no hashes should be - // needed std::vector hashes = - // t3->getNeededHashes(1, &filter); - // BEAST_EXPECT(hashes.empty(), "missing hashes"); - // - // BEAST_EXPECT(t3->getHash () == t2->getHash (), "root - // hashes do not match"); BEAST_EXPECT(t3->deepCompare - // (*t2), "failed compare"); - // } - // catch (std::exception const&) - // { - // fail ("unhandled exception"); - // } + BEAST_EXPECT(rebuilt->deepCompare(*source)); } }; diff --git a/src/xrpld/app/ledger/detail/LedgerMaster.cpp b/src/xrpld/app/ledger/detail/LedgerMaster.cpp index 3fcac03ed5..bab0dca827 100644 --- a/src/xrpld/app/ledger/detail/LedgerMaster.cpp +++ b/src/xrpld/app/ledger/detail/LedgerMaster.cpp @@ -137,7 +137,7 @@ LedgerMaster::LedgerMaster( std::chrono::seconds{45}, stopwatch, app_.getJournal("TaggedCache")) - , stats_(std::bind(&LedgerMaster::collectMetrics, this), collector) + , stats_([this] { collectMetrics(); }, collector) { } diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index d1f794b74d..4d40247a29 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -330,7 +330,7 @@ public: , jobQueue_(jobQueue) , standalone_(standalone) , minPeerCount_(startValid ? 0 : minPeerCount) - , stats_(std::bind(&NetworkOPsImp::collectMetrics, this), collector) + , stats_([this] { collectMetrics(); }, collector) { } diff --git a/src/xrpld/app/misc/SHAMapStoreImp.cpp b/src/xrpld/app/misc/SHAMapStoreImp.cpp index 0389130f7a..0e0099cdbf 100644 --- a/src/xrpld/app/misc/SHAMapStoreImp.cpp +++ b/src/xrpld/app/misc/SHAMapStoreImp.cpp @@ -331,11 +331,9 @@ SHAMapStoreImp::run() try { validatedLedger->stateMap().snapShot(false)->visitNodes( - std::bind( - &SHAMapStoreImp::copyNode, - this, - std::ref(nodeCount), - std::placeholders::_1)); + [this, &nodeCount](SHAMapTreeNode const& node) { + return copyNode(nodeCount, node); + }); } catch (SHAMapMissingNode const& e) { diff --git a/src/xrpld/app/misc/detail/WorkBase.h b/src/xrpld/app/misc/detail/WorkBase.h index 5f5fdd28b7..73e5081036 100644 --- a/src/xrpld/app/misc/detail/WorkBase.h +++ b/src/xrpld/app/misc/detail/WorkBase.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -138,9 +139,9 @@ WorkBase::run() if (!strand_.running_in_this_thread()) { return boost::asio::post( - ios_, - boost::asio::bind_executor( - strand_, std::bind(&WorkBase::run, impl().shared_from_this()))); + ios_, boost::asio::bind_executor(strand_, [self = impl().shared_from_this()] { + self->run(); + })); } resolver_.async_resolve( @@ -148,11 +149,9 @@ WorkBase::run() port_, boost::asio::bind_executor( strand_, - std::bind( - &WorkBase::onResolve, - impl().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = impl().shared_from_this()](error_code const& ec, results_type results) { + self->onResolve(ec, results); + })); } template @@ -165,7 +164,7 @@ WorkBase::cancel() ios_, boost::asio::bind_executor( - strand_, std::bind(&WorkBase::cancel, impl().shared_from_this()))); + strand_, [self = impl().shared_from_this()] { self->cancel(); })); } error_code ec; @@ -196,11 +195,12 @@ WorkBase::onResolve(error_code const& ec, results_type results) results, boost::asio::bind_executor( strand_, - std::bind( - &WorkBase::onConnect, - impl().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = impl().shared_from_this()]( + error_code const& ec, endpoint_type const& endpoint) { + // Call the base-class overload explicitly: the derived Impl + // hides it with its own single-argument onConnect(ec). + self->WorkBase::onConnect(ec, endpoint); + })); } template @@ -229,8 +229,9 @@ WorkBase::onStart() impl().stream(), req_, boost::asio::bind_executor( - strand_, - std::bind(&WorkBase::onRequest, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onRequest(ec); + })); } template @@ -245,8 +246,9 @@ WorkBase::onRequest(error_code const& ec) readBuf_, res_, boost::asio::bind_executor( - strand_, - std::bind(&WorkBase::onResponse, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onResponse(ec); + })); } template diff --git a/src/xrpld/app/misc/detail/WorkFile.h b/src/xrpld/app/misc/detail/WorkFile.h index 2fc7ab952d..eb42d14db4 100644 --- a/src/xrpld/app/misc/detail/WorkFile.h +++ b/src/xrpld/app/misc/detail/WorkFile.h @@ -63,9 +63,9 @@ WorkFile::run() { if (!strand_.running_in_this_thread()) { - boost::asio::post( - ios_, - boost::asio::bind_executor(strand_, std::bind(&WorkFile::run, shared_from_this()))); + boost::asio::post(ios_, boost::asio::bind_executor(strand_, [self = shared_from_this()] { + self->run(); + })); return; } diff --git a/src/xrpld/app/misc/detail/WorkSSL.cpp b/src/xrpld/app/misc/detail/WorkSSL.cpp index e1b864e81f..e8d24b55d6 100644 --- a/src/xrpld/app/misc/detail/WorkSSL.cpp +++ b/src/xrpld/app/misc/detail/WorkSSL.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -55,7 +54,7 @@ WorkSSL::onConnect(error_code const& ec) stream_.async_handshake( boost::asio::ssl::stream_base::client, boost::asio::bind_executor( - strand_, std::bind(&WorkSSL::onHandshake, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onHandshake(ec); })); } void diff --git a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp index fd1298516f..338a3a33df 100644 --- a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp +++ b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp @@ -421,8 +421,9 @@ SQLiteDatabase::oldestAccountTxPage(AccountTxPageOptions const& options) return {}; static std::uint32_t const kPageLength(200); - auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); + auto onUnsavedLedger = [&app = registry_.get().getApp()](std::uint32_t seq) { + saveLedgerAsync(app, seq); + }; AccountTxs ret; auto onTransaction = [&ret, &app = registry_.get().getApp()]( std::uint32_t ledgerIndex, @@ -451,8 +452,9 @@ SQLiteDatabase::newestAccountTxPage(AccountTxPageOptions const& options) return {}; static std::uint32_t const kPageLength(200); - auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); + auto onUnsavedLedger = [&app = registry_.get().getApp()](std::uint32_t seq) { + saveLedgerAsync(app, seq); + }; AccountTxs ret; auto onTransaction = [&ret, &app = registry_.get().getApp()]( std::uint32_t ledgerIndex, @@ -481,8 +483,9 @@ SQLiteDatabase::oldestAccountTxPageB(AccountTxPageOptions const& options) return {}; static std::uint32_t const kPageLength(500); - auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); + auto onUnsavedLedger = [&app = registry_.get().getApp()](std::uint32_t seq) { + saveLedgerAsync(app, seq); + }; MetaTxsList ret; auto onTransaction = [&ret]( @@ -509,8 +512,9 @@ SQLiteDatabase::newestAccountTxPageB(AccountTxPageOptions const& options) return {}; static std::uint32_t const kPageLength(500); - auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); + auto onUnsavedLedger = [&app = registry_.get().getApp()](std::uint32_t seq) { + saveLedgerAsync(app, seq); + }; MetaTxsList ret; auto onTransaction = [&ret]( diff --git a/src/xrpld/overlay/detail/ConnectAttempt.cpp b/src/xrpld/overlay/detail/ConnectAttempt.cpp index 295f4f5497..064b4ecd3e 100644 --- a/src/xrpld/overlay/detail/ConnectAttempt.cpp +++ b/src/xrpld/overlay/detail/ConnectAttempt.cpp @@ -35,8 +35,8 @@ #include #include +#include #include -#include #include #include #include @@ -86,7 +86,7 @@ ConnectAttempt::stop() { if (!strand_.running_in_this_thread()) { - boost::asio::post(strand_, std::bind(&ConnectAttempt::stop, shared_from_this())); + boost::asio::post(strand_, [self = shared_from_this()] { self->stop(); }); return; } if (socket_.is_open()) @@ -104,8 +104,7 @@ ConnectAttempt::run() stream_.next_layer().async_connect( remoteEndpoint_, boost::asio::bind_executor( - strand_, - std::bind(&ConnectAttempt::onConnect, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onConnect(ec); })); } //------------------------------------------------------------------------------ @@ -160,8 +159,7 @@ ConnectAttempt::setTimer() timer_.async_wait( boost::asio::bind_executor( - strand_, - std::bind(&ConnectAttempt::onTimer, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); } void @@ -228,8 +226,7 @@ ConnectAttempt::onConnect(error_code ec) stream_.async_handshake( boost::asio::ssl::stream_base::client, boost::asio::bind_executor( - strand_, - std::bind(&ConnectAttempt::onHandshake, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onHandshake(ec); })); } void @@ -290,7 +287,7 @@ ConnectAttempt::onHandshake(error_code ec) req_, boost::asio::bind_executor( strand_, - std::bind(&ConnectAttempt::onWrite, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec, std::size_t) { self->onWrite(ec); })); } void @@ -316,7 +313,7 @@ ConnectAttempt::onWrite(error_code ec) response_, boost::asio::bind_executor( strand_, - std::bind(&ConnectAttempt::onRead, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec, std::size_t) { self->onRead(ec); })); } void @@ -339,8 +336,7 @@ ConnectAttempt::onRead(error_code ec) stream_.async_shutdown( boost::asio::bind_executor( strand_, - std::bind( - &ConnectAttempt::onShutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); return; } diff --git a/src/xrpld/overlay/detail/OverlayImpl.cpp b/src/xrpld/overlay/detail/OverlayImpl.cpp index 89c7dfe5eb..b7af3b6ace 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.cpp +++ b/src/xrpld/overlay/detail/OverlayImpl.cpp @@ -133,7 +133,7 @@ OverlayImpl::Timer::asyncWait() timer.async_wait( boost::asio::bind_executor( overlay_.strand_, - std::bind(&Timer::onTimer, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); } void @@ -190,7 +190,7 @@ OverlayImpl::OverlayImpl( , nextId_(1) , slots_(app, *this, app.config()) , stats_( - std::bind(&OverlayImpl::collectMetrics, this), + [this] { collectMetrics(); }, collector, [counts = traffic_.getCounts(), collector]() { std::unordered_map ret; @@ -593,7 +593,7 @@ OverlayImpl::start() void OverlayImpl::stop() { - boost::asio::dispatch(strand_, std::bind(&OverlayImpl::stopChildren, this)); + boost::asio::dispatch(strand_, [this] { stopChildren(); }); { std::unique_lock lock(mutex_); cond_.wait(lock, [this] { return list_.empty(); }); @@ -1490,7 +1490,7 @@ OverlayImpl::deletePeer(Peer::id_t id) { if (!strand_.running_in_this_thread()) { - post(strand_, std::bind(&OverlayImpl::deletePeer, this, id)); + post(strand_, [this, id] { deletePeer(id); }); return; } @@ -1502,7 +1502,7 @@ OverlayImpl::deleteIdlePeers() { if (!strand_.running_in_this_thread()) { - post(strand_, std::bind(&OverlayImpl::deleteIdlePeers, this)); + post(strand_, [this] { deleteIdlePeers(); }); return; } diff --git a/src/xrpld/overlay/detail/OverlayImpl.h b/src/xrpld/overlay/detail/OverlayImpl.h index 7db32c0d23..83d5a81a89 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.h +++ b/src/xrpld/overlay/detail/OverlayImpl.h @@ -427,7 +427,7 @@ public: addTxMetrics(Args... args) { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&OverlayImpl::addTxMetrics, this, args...)); + return post(strand_, [this, args...] { addTxMetrics(args...); }); txMetrics_.addMetrics(args...); } diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index 83e4d9c851..4e42d46f46 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -321,9 +321,9 @@ PeerImp::send(std::shared_ptr const& m) self->stream_, boost::asio::buffer(self->sendQueue_.front()->getBuffer(self->compressionEnabled_)), bind_executor( - self->strand_, - std::bind( - &PeerImp::onWriteMessage, self, std::placeholders::_1, std::placeholders::_2))); + self->strand_, [self](error_code const& ec, std::size_t bytesTransferred) { + self->onWriteMessage(ec, bytesTransferred); + })); }); } @@ -650,7 +650,7 @@ PeerImp::gracefulClose() return; setTimer(); stream_.async_shutdown(bind_executor( - strand_, std::bind(&PeerImp::onShutdown, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); } void @@ -666,7 +666,7 @@ PeerImp::setTimer() return; } timer_.async_wait(bind_executor( - strand_, std::bind(&PeerImp::onTimer, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); } // convenience for ignoring the error code @@ -975,11 +975,9 @@ PeerImp::onReadMessage(error_code ec, std::size_t bytesTransferred) readBuffer_.prepare(std::max(Tuning::kReadBufferBytes, hint)), bind_executor( strand_, - std::bind( - &PeerImp::onReadMessage, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()](error_code const& ec, std::size_t bytesTransferred) { + self->onReadMessage(ec, bytesTransferred); + })); } void @@ -1014,18 +1012,16 @@ PeerImp::onWriteMessage(error_code ec, std::size_t bytesTransferred) boost::asio::buffer(sendQueue_.front()->getBuffer(compressionEnabled_)), bind_executor( strand_, - std::bind( - &PeerImp::onWriteMessage, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()](error_code const& ec, std::size_t bytesTransferred) { + self->onWriteMessage(ec, bytesTransferred); + })); return; } if (gracefulClose_) { stream_.async_shutdown(bind_executor( - strand_, std::bind(&PeerImp::onShutdown, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); return; } } diff --git a/src/xrpld/peerfinder/detail/Checker.h b/src/xrpld/peerfinder/detail/Checker.h index 20687448df..208bad390c 100644 --- a/src/xrpld/peerfinder/detail/Checker.h +++ b/src/xrpld/peerfinder/detail/Checker.h @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -183,7 +182,7 @@ Checker::asyncConnect(beast::IP::Endpoint const& endpoint, Handler&& h } op->socket.async_connect( beast::IPAddressConversion::toAsioEndpoint(endpoint), - std::bind(&BasicAsyncOp::operator(), op, std::placeholders::_1)); + [op](error_code const& ec) { (*op)(ec); }); } template diff --git a/src/xrpld/peerfinder/detail/Logic.h b/src/xrpld/peerfinder/detail/Logic.h index 7d10f7f516..8ea348f560 100644 --- a/src/xrpld/peerfinder/detail/Logic.h +++ b/src/xrpld/peerfinder/detail/Logic.h @@ -802,12 +802,10 @@ public: // checker.asyncConnect( ep.address, - std::bind( - &Logic::checkComplete, - this, - slot->remoteEndpoint(), - ep.address, - std::placeholders::_1)); + [this, remoteAddress = slot->remoteEndpoint(), checkedAddress = ep.address]( + boost::system::error_code const& ec) { + checkComplete(remoteAddress, checkedAddress, ec); + }); // Note that we simply discard the first Endpoint // that the neighbor sends when we perform the diff --git a/src/xrpld/peerfinder/detail/PeerfinderManager.cpp b/src/xrpld/peerfinder/detail/PeerfinderManager.cpp index 9dbedfe4f1..2727a03013 100644 --- a/src/xrpld/peerfinder/detail/PeerfinderManager.cpp +++ b/src/xrpld/peerfinder/detail/PeerfinderManager.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -61,7 +60,7 @@ public: , checker_(io_context_) , logic_(clock, store_, checker_, journal) , config_(config) - , stats_(std::bind(&ManagerImp::collectMetrics, this), collector) + , stats_([this] { collectMetrics(); }, collector) { } diff --git a/src/xrpld/rpc/detail/Pathfinder.cpp b/src/xrpld/rpc/detail/Pathfinder.cpp index fc788dea7d..5b7f1415a2 100644 --- a/src/xrpld/rpc/detail/Pathfinder.cpp +++ b/src/xrpld/rpc/detail/Pathfinder.cpp @@ -1158,11 +1158,10 @@ Pathfinder::addLink( { std::ranges::sort( candidates, - std::bind( - compareAccountCandidate, - ledger_->seq(), - std::placeholders::_1, - std::placeholders::_2)); + [seq = ledger_->seq()]( + AccountCandidate const& first, AccountCandidate const& second) { + return compareAccountCandidate(seq, first, second); + }); int count = candidates.size(); // allow more paths from source diff --git a/src/xrpld/rpc/detail/RPCCall.cpp b/src/xrpld/rpc/detail/RPCCall.cpp index 123b9fc7a5..af5677008d 100644 --- a/src/xrpld/rpc/detail/RPCCall.cpp +++ b/src/xrpld/rpc/detail/RPCCall.cpp @@ -1745,7 +1745,9 @@ rpcClient( static_cast(setup.client.secure) != 0, // Use SSL config.quiet(), logs, - std::bind(RPCCallImp::callRPCHandler, &jvOutput, std::placeholders::_1), + [&jvOutput](json::Value const& jvInput) { + RPCCallImp::callRPCHandler(&jvOutput, jvInput); + }, headers); isService.run(); // This blocks until there are no more // outstanding async calls. @@ -1870,24 +1872,16 @@ fromNetwork( ioContext, strIp, iPort, - std::bind( - &RPCCallImp::onRequest, - strMethod, - jvParams, - headers, - strPath, - std::placeholders::_1, - std::placeholders::_2, - j), + [strMethod, jvParams, headers, strPath, j]( + boost::asio::streambuf& sb, std::string const& strHost) { + RPCCallImp::onRequest(strMethod, jvParams, headers, strPath, sb, strHost, j); + }, kRpcReplyMaxBytes, kRpcWebhookTimeout, - std::bind( - &RPCCallImp::onResponse, - callbackFuncP, - std::placeholders::_1, - std::placeholders::_2, - std::placeholders::_3, - j), + [callbackFuncP, j]( + boost::system::error_code const& ecResult, int iStatus, std::string const& strData) { + return RPCCallImp::onResponse(callbackFuncP, ecResult, iStatus, strData, j); + }, j); }