mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-28 09:30:34 +00:00
chore: Enable modernize-avoid-bind (#7711)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -45,7 +45,10 @@ public:
|
||||
template <class F, class... Args>
|
||||
explicit Thread(Suite& s, F&& f, Args&&... args) : s_(&s)
|
||||
{
|
||||
std::function<void(void)> b = std::bind(std::forward<F>(f), std::forward<Args>(args)...);
|
||||
std::function<void(void)> b = [f = std::forward<F>(f),
|
||||
... args = std::forward<Args>(args)]() mutable {
|
||||
std::invoke(f, args...);
|
||||
};
|
||||
t_ = std::thread(&Thread::run, this, std::move(b));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/tls1.h>
|
||||
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,10 +223,7 @@ BaseHTTPPeer<Handler, Impl>::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<Handler, Impl>::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<Handler, Impl>::doRead,
|
||||
impl().shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
util::spawn(strand_, [self = impl().shared_from_this()](yield_context doYield) {
|
||||
self->doRead(doYield);
|
||||
});
|
||||
}
|
||||
|
||||
template <class Handler, class Impl>
|
||||
@@ -351,14 +344,9 @@ BaseHTTPPeer<Handler, Impl>::doWriter(
|
||||
{
|
||||
auto const p = impl().shared_from_this();
|
||||
resume = std::function<void(void)>([this, p, writer, keepAlive]() {
|
||||
util::spawn(
|
||||
strand_,
|
||||
std::bind(
|
||||
&BaseHTTPPeer<Handler, Impl>::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<Handler, Impl>::doWriter(
|
||||
if (!keepAlive)
|
||||
return doClose();
|
||||
|
||||
util::spawn(
|
||||
strand_,
|
||||
std::bind(
|
||||
&BaseHTTPPeer<Handler, Impl>::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<Handler, Impl>::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<Handler, Impl>::write(std::shared_ptr<Writer> const& writer, bool keepAlive)
|
||||
{
|
||||
util::spawn(
|
||||
strand_,
|
||||
std::bind(
|
||||
&BaseHTTPPeer<Handler, Impl>::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<Handler, Impl>::complete()
|
||||
{
|
||||
if (!strand_.running_in_this_thread())
|
||||
{
|
||||
return post(
|
||||
strand_, std::bind(&BaseHTTPPeer<Handler, Impl>::complete, impl().shared_from_this()));
|
||||
return post(strand_, [self = impl().shared_from_this()] { self->complete(); });
|
||||
}
|
||||
|
||||
message_ = {};
|
||||
@@ -457,12 +436,9 @@ BaseHTTPPeer<Handler, Impl>::complete()
|
||||
}
|
||||
|
||||
// keep-alive
|
||||
util::spawn(
|
||||
strand_,
|
||||
std::bind(
|
||||
&BaseHTTPPeer<Handler, Impl>::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<Handler, Impl>::close(bool graceful)
|
||||
if (!strand_.running_in_this_thread())
|
||||
{
|
||||
return post(
|
||||
strand_,
|
||||
std::bind(
|
||||
(void (BaseHTTPPeer::*)(bool))&BaseHTTPPeer<Handler, Impl>::close,
|
||||
impl().shared_from_this(),
|
||||
graceful));
|
||||
strand_, [self = impl().shared_from_this(), graceful] { self->close(graceful); });
|
||||
}
|
||||
|
||||
complete_ = true;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -84,7 +83,7 @@ void
|
||||
BasePeer<Handler, Impl>::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);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
@@ -180,12 +181,13 @@ void
|
||||
BaseWSPeer<Handler, Impl>::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<Handler, Impl>::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 <class Handler, class Impl>
|
||||
@@ -205,7 +205,10 @@ void
|
||||
BaseWSPeer<Handler, Impl>::send(std::shared_ptr<WSMsg> 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<Handler, Impl>::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<Handler, Impl>::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<Handler, Impl>::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<Handler, Impl>::onWrite(error_code const& ec)
|
||||
static_cast<bool>(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<Handler, Impl>::onWrite(error_code const& ec)
|
||||
static_cast<bool>(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<Handler, Impl>::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<Handler, Impl>::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 <class Handler, class Impl>
|
||||
@@ -389,11 +392,7 @@ BaseWSPeer<Handler, Impl>::startTimer()
|
||||
}
|
||||
|
||||
timer_.async_wait(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&BaseWSPeer<Handler, Impl>::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<Handler, Impl>::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;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
@@ -182,7 +181,7 @@ void
|
||||
Door<Handler>::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 <class Handler>
|
||||
@@ -297,8 +296,7 @@ void
|
||||
Door<Handler>::run()
|
||||
{
|
||||
util::spawn(
|
||||
strand_,
|
||||
std::bind(&Door<Handler>::doAccept, this->shared_from_this(), std::placeholders::_1));
|
||||
strand_, [self = this->shared_from_this()](yield_context yield) { self->doAccept(yield); });
|
||||
}
|
||||
|
||||
template <class Handler>
|
||||
@@ -307,8 +305,7 @@ Door<Handler>::close()
|
||||
{
|
||||
if (!strand_.running_in_this_thread())
|
||||
{
|
||||
return boost::asio::post(
|
||||
strand_, std::bind(&Door<Handler>::close, this->shared_from_this()));
|
||||
return boost::asio::post(strand_, [self = this->shared_from_this()] { self->close(); });
|
||||
}
|
||||
backoffTimer_.cancel();
|
||||
error_code ec;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <boost/beast/core/tcp_stream.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
@@ -89,7 +88,9 @@ PlainHTTPPeer<Handler>::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<Handler>::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 <class Handler>
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <boost/beast/core/tcp_stream.hpp>
|
||||
#include <boost/beast/ssl/ssl_stream.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
@@ -99,14 +98,15 @@ SSLHTTPPeer<Handler>::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 <class Handler>
|
||||
@@ -142,9 +142,9 @@ SSLHTTPPeer<Handler>::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<Handler>::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 <class Handler>
|
||||
|
||||
Reference in New Issue
Block a user