mirror of
https://github.com/espressif/openthread.git
synced 2026-07-27 06:17:47 +00:00
[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:
+1
-15
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user