diff --git a/net/BUILD b/net/BUILD index 2298e69..4620d70 100644 --- a/net/BUILD +++ b/net/BUILD @@ -96,6 +96,7 @@ cc_library( ":timer-list", "//base:types", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/functional:any_invocable", "@org_boost_boost//:endian", "@org_boost_boost//:process", "@org_boost_boost//:smart_ptr", diff --git a/net/icmp-client.cc b/net/icmp-client.cc index 172f820..3844965 100644 --- a/net/icmp-client.cc +++ b/net/icmp-client.cc @@ -45,7 +45,7 @@ class IcmpClient::Operation : public boost::intrusive_ref_counter< IcmpClient &client, const icmp::endpoint &endpoint, uint16_t sequence_number, - std::function callback); + absl::AnyInvocable callback); ~Operation(); Operation(const Operation &) = delete; @@ -58,7 +58,7 @@ class IcmpClient::Operation : public boost::intrusive_ref_counter< IcmpClient &client_; icmp::endpoint endpoint_; uint16_t sequence_number_; - std::function callback_; + absl::AnyInvocable callback_; std::optional timer_; IcmpHeader request_header_; }; @@ -76,10 +76,10 @@ IcmpClient::IcmpClient(const any_io_executor &executor, const Options &options) void IcmpClient::request( const icmp::endpoint &endpoint, ConstBufferSpan buffer, - std::function callback) { + absl::AnyInvocable callback) { uint16_t sequence_number = next_sequence_number_; if (operations_.find(sequence_number) != operations_.end()) { - callback(make_error_code(std::errc::no_buffer_space), {}); + std::move(callback)(make_error_code(std::errc::no_buffer_space), {}); return; } ++next_sequence_number_; @@ -125,7 +125,7 @@ IcmpClient::Operation::Operation( IcmpClient &client, const icmp::endpoint &endpoint, uint16_t sequence_number, - std::function callback) + absl::AnyInvocable callback) : client_(client), endpoint_(endpoint), sequence_number_(sequence_number), @@ -158,7 +158,7 @@ void IcmpClient::Operation::start(ConstBufferSpan buffer) { } void IcmpClient::Operation::finish(std::error_code ec, ConstBufferSpan buffer) { - callback_(ec, buffer); + std::move(callback_)(ec, buffer); intrusive_ptr_release(this); } diff --git a/net/icmp-client.h b/net/icmp-client.h index aff7e48..3debfaf 100644 --- a/net/icmp-client.h +++ b/net/icmp-client.h @@ -3,11 +3,11 @@ #include #include -#include #include #include #include "absl/container/flat_hash_map.h" +#include "absl/functional/any_invocable.h" #include "base/types.h" #include "net/asio.h" #include "net/timer-list.h" @@ -31,7 +31,7 @@ class IcmpClient { void request( const icmp::endpoint &endpoint, ConstBufferSpan buffer, - std::function callback); + absl::AnyInvocable callback); private: class Operation;