浏览代码

let the socketAddress cache be global

UbitUmarov 3 周之前
父节点
当前提交
8e6eeb1931
共有 2 个文件被更改,包括 18 次插入15 次删除
  1. 17 5
      OpenSim/Framework/Util.cs
  2. 1 10
      OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs

+ 17 - 5
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)

+ 1 - 10
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++;