From 8e6eeb193158d9b2b61f01a8c13a546e52712784 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 27 Apr 2024 15:47:33 +0100 Subject: [PATCH] let the socketAddress cache be global --- OpenSim/Framework/Util.cs | 22 ++++++++++++++----- .../ClientStack/Linden/UDP/OpenSimUDPBase.cs | 11 +--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index aa5755661c..bc4b00f3ee 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -1617,7 +1617,21 @@ namespace OpenSim.Framework return output.ToString(); } - private static readonly ExpiringCacheOS dnscache = new(10000); + private static IPEndPoint dummyIPEndPoint = new IPEndPoint(IPAddress.Any, 0); + private static readonly ExpiringCacheOS dnscache = new(30000); + private static readonly ExpiringCacheOS EndpointsCache = new(300000); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static EndPoint GetEndPoint(SocketAddress sckaddr) + { + if (!EndpointsCache.TryGetValue(sckaddr, 300000, out EndPoint ep)) + { + ep = dummyIPEndPoint.Create(sckaddr); + EndpointsCache.AddOrUpdate(sckaddr, ep, 300); + } + return ep; + } + /// /// Converts a URL to a IPAddress @@ -1686,16 +1700,14 @@ namespace OpenSim.Framework if (ia == null) return null; - IPEndPoint newEP; try { - newEP = new IPEndPoint(ia, port); + return new IPEndPoint(ia, port); } catch { - newEP = null; + return null; } - return newEP; } public static IPEndPoint getEndPoint(string hostname, int port) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs index ea754ef9df..51f438a7c0 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs @@ -279,9 +279,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP IsRunningOutbound = false; } - private static IPEndPoint dummyIP = new IPEndPoint(IPAddress.Any, 0); - private static readonly ExpiringCacheOS IPEndpointsCache = new(300000); - private async void AsyncBeginReceive() { SocketAddress workSktAddress = new(m_udpSocket.AddressFamily); @@ -300,14 +297,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (nbytes > 0) { int startTick = Util.EnvironmentTickCount(); - if(!IPEndpointsCache.TryGetValue(workSktAddress, 300000, out EndPoint ep)) - { - ep = dummyIP.Create(workSktAddress); - IPEndpointsCache.AddOrUpdate(workSktAddress, ep, 300000); - } - - buf.RemoteEndPoint = ep; + buf.RemoteEndPoint = Util.GetEndPoint(workSktAddress);; buf.DataLength = nbytes; UdpReceives++;