diff --git a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp index a06ebe26559ffa..4bcfd8fa699612 100644 --- a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp @@ -724,29 +724,30 @@ FullQName AdvertiserMinMdns::GetCommissioningTxtEntries(const CommissionAdvertis bool AdvertiserMinMdns::ShouldAdvertiseOn(const chip::Inet::InterfaceId id, const chip::Inet::IPAddress & addr) { auto & server = GlobalMinimalMdnsServer::Server(); - for (unsigned i = 0; i < server.GetEndpointCount(); i++) - { - const ServerBase::EndpointInfo & info = server.GetEndpoints()[i]; - if (info.listen_udp == nullptr) + bool result = false; + + server.ForEachEndPoints([&](auto * info) { + if (info->mListenUdp == nullptr) { - continue; + return chip::Loop::Continue; } - if (info.interfaceId != id) + if (info->mInterfaceId != id) { - continue; + return chip::Loop::Continue; } - if (info.addressType != addr.Type()) + if (info->mAddressType != addr.Type()) { - continue; + return chip::Loop::Continue; } - return true; - } + result = true; + return chip::Loop::Break; + }); - return false; + return result; } void AdvertiserMinMdns::AdvertiseRecords() diff --git a/src/lib/dnssd/minimal_mdns/Server.cpp b/src/lib/dnssd/minimal_mdns/Server.cpp index 792c677582a2fc..3b80d797d1de94 100644 --- a/src/lib/dnssd/minimal_mdns/Server.cpp +++ b/src/lib/dnssd/minimal_mdns/Server.cpp @@ -54,7 +54,7 @@ class ShutdownOnError class ListenSocketPickerDelegate : public ServerBase::BroadcastSendDelegate { public: - chip::Inet::UDPEndPoint * Accept(ServerBase::EndpointInfo * info) override { return info->listen_udp; } + chip::Inet::UDPEndPoint * Accept(ServerBase::EndpointInfo * info) override { return info->mListenUdp; } }; #if CHIP_MINMDNS_USE_EPHEMERAL_UNICAST_PORT @@ -65,7 +65,7 @@ class ListenSocketPickerDelegate : public ServerBase::BroadcastSendDelegate class QuerySocketPickerDelegate : public ServerBase::BroadcastSendDelegate { public: - chip::Inet::UDPEndPoint * Accept(ServerBase::EndpointInfo * info) override { return info->unicast_query_udp; } + chip::Inet::UDPEndPoint * Accept(ServerBase::EndpointInfo * info) override { return info->mUnicastQueryUdp; } }; #else @@ -96,12 +96,12 @@ class InterfaceTypeFilterDelegate : public ServerBase::BroadcastSendDelegate chip::Inet::UDPEndPoint * Accept(ServerBase::EndpointInfo * info) override { - if ((info->interfaceId != mInterface) && (info->interfaceId != chip::Inet::InterfaceId::Null())) + if ((info->mInterfaceId != mInterface) && (info->mInterfaceId != chip::Inet::InterfaceId::Null())) { return nullptr; } - if ((mAddressType != chip::Inet::IPAddressType::kAny) && (info->addressType != mAddressType)) + if ((mAddressType != chip::Inet::IPAddressType::kAny) && (info->mAddressType != mAddressType)) { return nullptr; } @@ -180,23 +180,6 @@ const char * AddressTypeStr(chip::Inet::IPAddressType addressType) } } -void ShutdownEndpoint(mdns::Minimal::ServerBase::EndpointInfo & aEndpoint) -{ - if (aEndpoint.listen_udp != nullptr) - { - aEndpoint.listen_udp->Free(); - aEndpoint.listen_udp = nullptr; - } - -#if CHIP_MINMDNS_USE_EPHEMERAL_UNICAST_PORT - if (aEndpoint.unicast_query_udp != nullptr) - { - aEndpoint.unicast_query_udp->Free(); - aEndpoint.unicast_query_udp = nullptr; - } -#endif -} - } // namespace ServerBase::~ServerBase() @@ -206,29 +189,35 @@ ServerBase::~ServerBase() void ServerBase::Shutdown() { - for (size_t i = 0; i < mEndpointCount; i++) - { - ShutdownEndpoint(mEndpoints[i]); - } + mEndpoints.ForEachActiveObject([&](auto * endpoint) { + ShutdownEndpoint(*endpoint); + return chip::Loop::Continue; + }); +} + +void ServerBase::ShutdownEndpoint(EndpointInfo & aEndpoint) +{ + mEndpoints.ReleaseObject(&aEndpoint); } bool ServerBase::IsListening() const { - for (size_t i = 0; i < mEndpointCount; i++) - { - if (mEndpoints[i].listen_udp != nullptr) + bool listening = false; + mEndpoints.ForEachActiveObject([&](auto * endpoint) { + if (endpoint->mListenUdp != nullptr) { - return true; + listening = true; + return chip::Loop::Break; } - } - return false; + return chip::Loop::Continue; + }); + return listening; } CHIP_ERROR ServerBase::Listen(chip::Inet::InetLayer * inetLayer, ListenIterator * it, uint16_t port) { Shutdown(); // ensure everything starts fresh - size_t endpointIndex = 0; chip::Inet::InterfaceId interfaceId = chip::Inet::InterfaceId::Null(); chip::Inet::IPAddressType addressType; @@ -236,19 +225,15 @@ CHIP_ERROR ServerBase::Listen(chip::Inet::InetLayer * inetLayer, ListenIterator while (it->Next(&interfaceId, &addressType)) { - ReturnErrorCodeIf(endpointIndex >= mEndpointCount, CHIP_ERROR_NO_MEMORY); - - EndpointInfo * info = &mEndpoints[endpointIndex]; - info->addressType = addressType; - info->interfaceId = interfaceId; - - ReturnErrorOnFailure(inetLayer->GetUDPEndPointManager()->NewEndPoint(&info->listen_udp)); + chip::Inet::UDPEndPoint * listenUdp; + ReturnErrorOnFailure(inetLayer->GetUDPEndPointManager()->NewEndPoint(&listenUdp)); + std::unique_ptr endPointHolder(listenUdp, {}); - ReturnErrorOnFailure(info->listen_udp->Bind(addressType, chip::Inet::IPAddress::Any, port, interfaceId)); + ReturnErrorOnFailure(listenUdp->Bind(addressType, chip::Inet::IPAddress::Any, port, interfaceId)); - ReturnErrorOnFailure(info->listen_udp->Listen(OnUdpPacketReceived, nullptr /*OnReceiveError*/, this)); + ReturnErrorOnFailure(listenUdp->Listen(OnUdpPacketReceived, nullptr /*OnReceiveError*/, this)); - CHIP_ERROR err = JoinMulticastGroup(interfaceId, info->listen_udp, addressType); + CHIP_ERROR err = JoinMulticastGroup(interfaceId, listenUdp, addressType); if (err != CHIP_NO_ERROR) { char interfaceName[chip::Inet::InterfaceId::kMaxIfNameLength]; @@ -257,11 +242,6 @@ CHIP_ERROR ServerBase::Listen(chip::Inet::InetLayer * inetLayer, ListenIterator // Log only as non-fatal error. Failure to join will mean we reply to unicast queries only. ChipLogError(DeviceLayer, "MDNS failed to join multicast group on %s for address type %s: %s", interfaceName, AddressTypeStr(addressType), chip::ErrorStr(err)); - ShutdownEndpoint(mEndpoints[endpointIndex]); - } - else - { - endpointIndex++; } #if CHIP_MINMDNS_USE_EPHEMERAL_UNICAST_PORT @@ -269,9 +249,25 @@ CHIP_ERROR ServerBase::Listen(chip::Inet::InetLayer * inetLayer, ListenIterator // - helps in not having conflicts on port 5353, will receive unicast replies directly // - has a *DRAWBACK* of unicast queries being considered LEGACY by mdns since they do // not originate from 5353 and the answers will include a query section. - ReturnErrorOnFailure(inetLayer->GetUDPEndPointManager()->NewEndPoint(&info->unicast_query_udp)); - ReturnErrorOnFailure(info->unicast_query_udp->Bind(addressType, chip::Inet::IPAddress::Any, 0, interfaceId)); - ReturnErrorOnFailure(info->unicast_query_udp->Listen(OnUdpPacketReceived, nullptr /*OnReceiveError*/, this)); + chip::Inet::UDPEndPoint * unicastQueryUdp; + ReturnErrorOnFailure(inetLayer->GetUDPEndPointManager()->NewEndPoint(&unicastQueryUdp)); + std::unique_ptr endPointHolderUnicast(unicastQueryUdp, {}); + ReturnErrorOnFailure(unicastQueryUdp->Bind(addressType, chip::Inet::IPAddress::Any, 0, interfaceId)); + ReturnErrorOnFailure(unicastQueryUdp->Listen(OnUdpPacketReceived, nullptr /*OnReceiveError*/, this)); +#endif + +#if CHIP_MINMDNS_USE_EPHEMERAL_UNICAST_PORT + if (endPointHolder || endPointHolderUnicast) + { + // If allocation fails, the rref will not be consumed, so that the endpoint will also be freed correctly + mEndpoints.CreateObject(interfaceId, addressType, std::move(endPointHolder), std::move(endPointHolderUnicast)); + } +#else + if (endPointHolder) + { + // If allocation fails, the rref will not be consumed, so that the endpoint will also be freed correctly + mEndpoints.CreateObject(interfaceId, addressType, std::move(endPointHolder)); + } #endif } @@ -281,30 +277,30 @@ CHIP_ERROR ServerBase::Listen(chip::Inet::InetLayer * inetLayer, ListenIterator CHIP_ERROR ServerBase::DirectSend(chip::System::PacketBufferHandle && data, const chip::Inet::IPAddress & addr, uint16_t port, chip::Inet::InterfaceId interface) { - for (size_t i = 0; i < mEndpointCount; i++) - { - EndpointInfo * info = &mEndpoints[i]; - if (info->listen_udp == nullptr) + CHIP_ERROR err = CHIP_ERROR_NOT_CONNECTED; + mEndpoints.ForEachActiveObject([&](auto * info) { + if (info->mListenUdp == nullptr) { - continue; + return chip::Loop::Continue; } - if (info->addressType != addr.Type()) + if (info->mAddressType != addr.Type()) { - continue; + return chip::Loop::Continue; } - chip::Inet::InterfaceId boundIf = info->listen_udp->GetBoundInterface(); + chip::Inet::InterfaceId boundIf = info->mListenUdp->GetBoundInterface(); if ((boundIf.IsPresent()) && (boundIf != interface)) { - continue; + return chip::Loop::Continue; } - return info->listen_udp->SendTo(addr, port, std::move(data)); - } + err = info->mListenUdp->SendTo(addr, port, std::move(data)); + return chip::Loop::Break; + }); - return CHIP_ERROR_NOT_CONNECTED; + return err; } CHIP_ERROR ServerBase::BroadcastUnicastQuery(chip::System::PacketBufferHandle && data, uint16_t port) @@ -350,49 +346,51 @@ CHIP_ERROR ServerBase::BroadcastImpl(chip::System::PacketBufferHandle && data, u bool hadSuccesfulSend = false; CHIP_ERROR lastError = CHIP_ERROR_NO_ENDPOINT; - for (size_t i = 0; i < mEndpointCount; i++) - { - EndpointInfo * info = &mEndpoints[i]; - chip::Inet::UDPEndPoint * udp = delegate->Accept(info); - - if (udp == nullptr) - { - continue; - } - - CHIP_ERROR err; - - /// The same packet needs to be sent over potentially multiple interfaces. - /// LWIP does not like having a pbuf sent over serparate interfaces, hence we create a copy - /// for sending via `CloneData` - /// - /// TODO: this wastes one copy of the data and that could be optimized away - if (info->addressType == chip::Inet::IPAddressType::kIPv6) - { - err = udp->SendTo(mIpv6BroadcastAddress, port, data.CloneData(), udp->GetBoundInterface()); - } + if (chip::Loop::Break == mEndpoints.ForEachActiveObject([&](auto * info) { + chip::Inet::UDPEndPoint * udp = delegate->Accept(info); + + if (udp == nullptr) + { + return chip::Loop::Continue; + } + + CHIP_ERROR err; + + /// The same packet needs to be sent over potentially multiple interfaces. + /// LWIP does not like having a pbuf sent over serparate interfaces, hence we create a copy + /// for sending via `CloneData` + /// + /// TODO: this wastes one copy of the data and that could be optimized away + if (info->mAddressType == chip::Inet::IPAddressType::kIPv6) + { + err = udp->SendTo(mIpv6BroadcastAddress, port, data.CloneData(), udp->GetBoundInterface()); + } #if INET_CONFIG_ENABLE_IPV4 - else if (info->addressType == chip::Inet::IPAddressType::kIPv4) - { - err = udp->SendTo(mIpv4BroadcastAddress, port, data.CloneData(), udp->GetBoundInterface()); - } + else if (info->mAddressType == chip::Inet::IPAddressType::kIPv4) + { + err = udp->SendTo(mIpv4BroadcastAddress, port, data.CloneData(), udp->GetBoundInterface()); + } #endif - else - { - // This is a general error of internal consistency: every address has a known type - // Fail completely otherwise. - return CHIP_ERROR_INCORRECT_STATE; - } - - if (err == CHIP_NO_ERROR) - { - hadSuccesfulSend = true; - } - else - { - ChipLogError(Discovery, "Attempt to mDNS broadcast failed: %s", chip::ErrorStr(err)); - lastError = err; - } + else + { + // This is a general error of internal consistency: every address has a known type. Fail completely otherwise. + lastError = CHIP_ERROR_INCORRECT_STATE; + return chip::Loop::Break; + } + + if (err == CHIP_NO_ERROR) + { + hadSuccesfulSend = true; + } + else + { + ChipLogError(Discovery, "Attempt to mDNS broadcast failed: %s", chip::ErrorStr(err)); + lastError = err; + } + return chip::Loop::Continue; + })) + { + return lastError; } if (!hadSuccesfulSend) diff --git a/src/lib/dnssd/minimal_mdns/Server.h b/src/lib/dnssd/minimal_mdns/Server.h index 1c43e785ab2d5f..d471db071b18de 100644 --- a/src/lib/dnssd/minimal_mdns/Server.h +++ b/src/lib/dnssd/minimal_mdns/Server.h @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -75,13 +76,49 @@ class ServerDelegate class ServerBase { public: - struct EndpointInfo + class EndpointInfo { - chip::Inet::InterfaceId interfaceId = chip::Inet::InterfaceId::Null(); - chip::Inet::IPAddressType addressType; - chip::Inet::UDPEndPoint * listen_udp = nullptr; + public: + struct EndPointDeletor + { + void operator()(chip::Inet::UDPEndPoint * e) { e->Free(); } + }; + +#if CHIP_MINMDNS_USE_EPHEMERAL_UNICAST_PORT + EndpointInfo(chip::Inet::InterfaceId interfaceId, chip::Inet::IPAddressType addressType, + std::unique_ptr && listenUdp, + std::unique_ptr && unicastQueryUdp) : + mInterfaceId(interfaceId), + mAddressType(addressType), mListenUdp(listenUdp.release()), mUnicastQueryUdp(unicastQueryUdp.release()) + {} +#else + EndpointInfo(chip::Inet::InterfaceId interfaceId, chip::Inet::IPAddressType addressType, + std::unique_ptr && listenUdp) : + mInterfaceId(interfaceId), + mAddressType(addressType), mListenUdp(listenUdp.release()) + {} +#endif + + ~EndpointInfo() + { + if (mListenUdp != nullptr) + { + mListenUdp->Free(); + } + +#if CHIP_MINMDNS_USE_EPHEMERAL_UNICAST_PORT + if (mUnicastQueryUdp != nullptr) + { + mUnicastQueryUdp->Free(); + } +#endif + } + + const chip::Inet::InterfaceId mInterfaceId; + const chip::Inet::IPAddressType mAddressType; + chip::Inet::UDPEndPoint * const mListenUdp; #if CHIP_MINMDNS_USE_EPHEMERAL_UNICAST_PORT - chip::Inet::UDPEndPoint * unicast_query_udp = nullptr; + chip::Inet::UDPEndPoint * const mUnicastQueryUdp; #endif }; @@ -101,16 +138,17 @@ class ServerBase virtual chip::Inet::UDPEndPoint * Accept(ServerBase::EndpointInfo * info) = 0; }; - ServerBase(EndpointInfo * endpointStorage, size_t kStorageSize) : mEndpoints(endpointStorage), mEndpointCount(kStorageSize) - { - for (size_t i = 0; i < mEndpointCount; i++) - { - mEndpoints[i].listen_udp = nullptr; #if CHIP_MINMDNS_USE_EPHEMERAL_UNICAST_PORT - mEndpoints[i].unicast_query_udp = nullptr; + using EndpointInfoPoolType = chip::PoolInterface &&, + std::unique_ptr &&>; +#else + using EndpointInfoPoolType = chip::PoolInterface &&>; #endif - } + ServerBase(EndpointInfoPoolType & pool) : mEndpoints(pool) + { BroadcastIpAddresses::GetIpv6Into(mIpv6BroadcastAddress); #if INET_CONFIG_ENABLE_IPV4 @@ -122,6 +160,8 @@ class ServerBase /// Closes all currently open endpoints void Shutdown(); + void ShutdownEndpoint(EndpointInfo & aEndpoint); + /// Listen on the given interfaces/address types. /// /// Since mDNS uses link-local addresses, one generally wants to listen on all @@ -155,13 +195,12 @@ class ServerBase return *this; } - /// How many endpoints are availabe to be used by the server. - size_t GetEndpointCount() const { return mEndpointCount; } - - /// Get the endpoints that are used by this server - /// - /// Entries with non-null UDP are considered usable. - const EndpointInfo * GetEndpoints() const { return mEndpoints; } + /// Iterator through all Endpoints + template + chip::Loop ForEachEndPoints(Function && function) + { + return mEndpoints.ForEachActiveObject(std::forward(function)); + } /// A server is considered listening if any UDP endpoint is active. /// @@ -176,8 +215,7 @@ class ServerBase static void OnUdpPacketReceived(chip::Inet::UDPEndPoint * endPoint, chip::System::PacketBufferHandle && buffer, const chip::Inet::IPPacketInfo * info); - EndpointInfo * mEndpoints; // possible endpoints, to listen on multiple interfaces - const size_t mEndpointCount; // how many endpoints are allocated + EndpointInfoPoolType & mEndpoints; // possible endpoints, to listen on multiple interfaces ServerDelegate * mDelegate = nullptr; // Broadcast IP addresses are cached to not require a string parse every time @@ -188,15 +226,14 @@ class ServerBase #endif }; +// The PoolImpl impl is used as a base class because its destructor must be called after ServerBase's destructor. template -class Server : public ServerBase +class Server : private chip::PoolImpl, + public ServerBase { public: - Server() : ServerBase(mAllocatedStorage, kCount) {} + Server() : ServerBase(*static_cast(this)) {} ~Server() {} - -private: - EndpointInfo mAllocatedStorage[kCount]; }; } // namespace Minimal diff --git a/src/lib/dnssd/minimal_mdns/tests/BUILD.gn b/src/lib/dnssd/minimal_mdns/tests/BUILD.gn index dd73b0f24119f6..6612cfe250e7c4 100644 --- a/src/lib/dnssd/minimal_mdns/tests/BUILD.gn +++ b/src/lib/dnssd/minimal_mdns/tests/BUILD.gn @@ -38,6 +38,7 @@ chip_test_suite("tests") { "${chip_root}/src/lib/core", "${chip_root}/src/lib/dnssd", "${chip_root}/src/lib/dnssd/minimal_mdns", + "${chip_root}/src/transport/raw/tests:helpers", "${nlunit_test_root}:nlunit-test", ] } diff --git a/src/lib/dnssd/minimal_mdns/tests/CheckOnlyServer.h b/src/lib/dnssd/minimal_mdns/tests/CheckOnlyServer.h index 697475fa7118fa..250f304807bf80 100644 --- a/src/lib/dnssd/minimal_mdns/tests/CheckOnlyServer.h +++ b/src/lib/dnssd/minimal_mdns/tests/CheckOnlyServer.h @@ -71,11 +71,17 @@ void MakePrintableName(char (&location)[N], FullQName name) } // namespace -class CheckOnlyServer : public ServerBase, public ParserDelegate, public TxtRecordDelegate +class CheckOnlyServer : private chip::PoolImpl, + public ServerBase, + public ParserDelegate, + public TxtRecordDelegate { public: - CheckOnlyServer(nlTestSuite * inSuite) : ServerBase(nullptr, 0), mInSuite(inSuite) { Reset(); } - CheckOnlyServer() : ServerBase(nullptr, 0), mInSuite(nullptr) { Reset(); } + CheckOnlyServer(nlTestSuite * inSuite) : ServerBase(*static_cast(this)), mInSuite(inSuite) + { + Reset(); + } + CheckOnlyServer() : ServerBase(*static_cast(this)), mInSuite(nullptr) { Reset(); } ~CheckOnlyServer() {} // Parser delegates @@ -393,7 +399,11 @@ class CheckOnlyServer : public ServerBase, public ParserDelegate, public TxtReco struct ServerSwapper { - ServerSwapper(CheckOnlyServer * server) { chip::Dnssd::GlobalMinimalMdnsServer::Instance().SetReplacementServer(server); } + ServerSwapper(CheckOnlyServer * server) + { + chip::Dnssd::GlobalMinimalMdnsServer::Instance().Server().Shutdown(); + chip::Dnssd::GlobalMinimalMdnsServer::Instance().SetReplacementServer(server); + } ~ServerSwapper() { chip::Dnssd::GlobalMinimalMdnsServer::Instance().SetReplacementServer(nullptr); } }; diff --git a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp index 5cde77f9f90d4b..c7dedc87cf7cb6 100644 --- a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -213,7 +214,7 @@ void OperationalAdverts(nlTestSuite * inSuite, void * inContext) auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance(); NL_TEST_ASSERT(inSuite, mdnsAdvertiser.RemoveServices() == CHIP_NO_ERROR); - auto & server = reinterpret_cast(GlobalMinimalMdnsServer::Server()); + auto & server = static_cast(GlobalMinimalMdnsServer::Server()); server.SetTestSuite(inSuite); server.Reset(); @@ -341,7 +342,7 @@ void CommissionableAdverts(nlTestSuite * inSuite, void * inContext) auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance(); NL_TEST_ASSERT(inSuite, mdnsAdvertiser.RemoveServices() == CHIP_NO_ERROR); - auto & server = reinterpret_cast(GlobalMinimalMdnsServer::Server()); + auto & server = static_cast(GlobalMinimalMdnsServer::Server()); server.SetTestSuite(inSuite); server.Reset(); @@ -457,7 +458,7 @@ void CommissionableAndOperationalAdverts(nlTestSuite * inSuite, void * inContext auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance(); NL_TEST_ASSERT(inSuite, mdnsAdvertiser.RemoveServices() == CHIP_NO_ERROR); - auto & server = reinterpret_cast(GlobalMinimalMdnsServer::Server()); + auto & server = static_cast(GlobalMinimalMdnsServer::Server()); server.SetTestSuite(inSuite); server.Reset(); @@ -548,12 +549,15 @@ const nlTest sTests[] = { int TestAdvertiser(void) { chip::Platform::MemoryInit(); + chip::Test::IOContext context; + context.Init(); nlTestSuite theSuite = { "AdvertiserImplMinimal", sTests, nullptr, nullptr }; CheckOnlyServer server(&theSuite); test::ServerSwapper swapper(&server); auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance(); - mdnsAdvertiser.Init(nullptr); + mdnsAdvertiser.Init(&context.GetInetLayer()); nlTestRunner(&theSuite, &server); + server.Shutdown(); return nlTestRunnerStats(&theSuite); } diff --git a/src/lib/support/PoolWrapper.h b/src/lib/support/PoolWrapper.h index 2fe8e7d0ab285a..db08761a9b15ec 100644 --- a/src/lib/support/PoolWrapper.h +++ b/src/lib/support/PoolWrapper.h @@ -33,9 +33,9 @@ class PoolInterface virtual ~PoolInterface() {} - virtual U * CreateObject(ConstructorArguments &&... args) = 0; - virtual void ReleaseObject(U * element) = 0; - virtual void ResetObject(U * element, ConstructorArguments &&... args) = 0; + virtual U * CreateObject(ConstructorArguments... args) = 0; + virtual void ReleaseObject(U * element) = 0; + virtual void ResetObject(U * element, ConstructorArguments... args) = 0; template Loop ForEachActiveObject(Function && function) @@ -64,16 +64,13 @@ class PoolProxy> : public PoolInter PoolProxy() {} virtual ~PoolProxy() override {} - virtual U * CreateObject(ConstructorArguments &&... args) override - { - return Impl().CreateObject(std::forward(args)...); - } + virtual U * CreateObject(ConstructorArguments... args) override { return Impl().CreateObject(std::move(args)...); } virtual void ReleaseObject(U * element) override { Impl().ReleaseObject(static_cast(element)); } - virtual void ResetObject(U * element, ConstructorArguments &&... args) override + virtual void ResetObject(U * element, ConstructorArguments... args) override { - return Impl().ResetObject(static_cast(element), std::forward(args)...); + return Impl().ResetObject(static_cast(element), std::move(args)...); } protected: