let the socketAddress cache be global

UbitUmarov [2024-04-27 14:47:33]
let the socketAddress cache be global
Filename
OpenSim/Framework/Util.cs
OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index aa57556..bc4b00f 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<string, IPAddress> dnscache = new(10000);
+        private static IPEndPoint dummyIPEndPoint = new IPEndPoint(IPAddress.Any, 0);
+        private static readonly ExpiringCacheOS<string, IPAddress> dnscache = new(30000);
+        private static readonly ExpiringCacheOS<SocketAddress, EndPoint> 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;
+        }
+

         /// <summary>
         /// 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 ea754ef..51f438a 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<SocketAddress,EndPoint> 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++;
ViewGit