[udp] use LinkedList::ContainsMatching() in IsPortInUse() (#12498)

This commit simplifies `IsPortInUse()` by using `LinkedList` helper
`ContainsMatching()` instead of manually iterating over the
list of sockets. A `SocketHandle::Matches(uint16_t aSockPort)`
is added to support this.
This commit is contained in:
Abtin Keshavarzian
2026-02-20 11:11:27 -06:00
committed by GitHub
parent c73c600cdc
commit 49ba31d43b
2 changed files with 2 additions and 15 deletions
+1 -15
View File
@@ -486,21 +486,7 @@ exit:
return;
}
bool Udp::IsPortInUse(uint16_t aPort) const
{
bool found = false;
for (const SocketHandle &socket : mSockets)
{
if (socket.GetSockName().GetPort() == aPort)
{
found = true;
break;
}
}
return found;
}
bool Udp::IsPortInUse(uint16_t aPort) const { return mSockets.ContainsMatching(aPort); }
} // namespace Ip6
} // namespace ot
+1
View File
@@ -162,6 +162,7 @@ public:
#endif
private:
bool Matches(uint16_t aSockPort) const { return GetSockName().GetPort() == aSockPort; }
bool Matches(const MessageInfo &aMessageInfo) const;
void HandleUdpReceive(Message &aMessage, const MessageInfo &aMessageInfo)