From 0df9802aa30492db59b1ab8587af465e1a347f48 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 16 Oct 2022 17:36:17 +0100 Subject: [PATCH] use 'in' on PollService event args --- OpenSim/Framework/Console/RemoteConsole.cs | 12 ++-- .../HttpServer/PollServiceEventArgs.cs | 10 +-- .../HttpServer/PollServiceRequestManager.cs | 17 ++--- .../Caps/EventQueue/EventQueueGetModule.cs | 71 ++++++++----------- .../Linden/Caps/FetchLibDescModule.cs | 10 +-- .../Linden/Caps/GetAssetsModule.cs | 47 ++++++------ .../Linden/Caps/WebFetchInvDescModule.cs | 12 ++-- .../Scripting/LSLHttp/UrlModule.cs | 12 ++-- .../Region/Framework/Scenes/ScenePresence.cs | 2 +- .../Services/GridService/HypergridLinker.cs | 4 +- 10 files changed, 91 insertions(+), 106 deletions(-) diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs index 276b7fa5df..e4165d5d94 100755 --- a/OpenSim/Framework/Console/RemoteConsole.cs +++ b/OpenSim/Framework/Console/RemoteConsole.cs @@ -610,7 +610,7 @@ namespace OpenSim.Framework.Console // Check if there is anything to send. Return true if this client has // lines pending. - protected bool HasEvents(UUID RequestID, UUID sessionID) + protected bool HasEvents(in UUID RequestID, in UUID sessionID) { ConsoleConnection c = null; @@ -627,7 +627,7 @@ namespace OpenSim.Framework.Console } // Send all pending output to the client. - protected Hashtable GetEvents(UUID RequestID, UUID sessionID) + protected Hashtable GetEvents(in UUID RequestID, in UUID sessionID) { // Find the connection that goes with this client. ConsoleConnection c = null; @@ -716,17 +716,15 @@ namespace OpenSim.Framework.Console // This is really just a no-op. It generates what is sent // to the client if the poll times out without any events. - protected Hashtable NoEvents(UUID RequestID, UUID id) + protected Hashtable NoEvents(in UUID RequestID, in UUID id) { Hashtable result = new Hashtable(); XmlDocument xmldoc = new XmlDocument(); - XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, - "", ""); + XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); xmldoc.AppendChild(xmlnode); - XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession", - ""); + XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession", ""); xmldoc.AppendChild(rootElement); diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index e7b44b2936..2a225f3e6b 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -31,13 +31,13 @@ using OpenMetaverse; namespace OpenSim.Framework.Servers.HttpServer { - public delegate OSHttpResponse RequestMethod(UUID ID, OSHttpRequest request); - public delegate bool HasEventsMethod(UUID requestID, UUID pId); + public delegate OSHttpResponse RequestMethod(in UUID ID, OSHttpRequest request); + public delegate bool HasEventsMethod(in UUID requestID, in UUID pId); - public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId); + public delegate Hashtable GetEventsMethod(in UUID requestID, in UUID pId); - public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId); - public delegate void DropMethod(UUID requestID, UUID pId); + public delegate Hashtable NoEventsMethod(in UUID requestID, in UUID pId); + public delegate void DropMethod(in UUID requestID, in UUID pId); public class PollServiceEventArgs : EventArgs { diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index a84df2a28a..beb8d88ac2 100755 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -41,16 +41,14 @@ namespace OpenSim.Framework.Servers.HttpServer { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private ConcurrentQueue m_retryRequests = new ConcurrentQueue(); - - private int m_WorkerThreadCount = 0; + private readonly ConcurrentQueue m_retryRequests = new(); + private readonly int m_WorkerThreadCount = 0; private ObjectJobEngine m_workerPool; private Thread m_retrysThread; private bool m_running = false; - public PollServiceRequestManager( - bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout) + public PollServiceRequestManager(bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout) { m_WorkerThreadCount = (int)pWorkerThreadCount; } @@ -59,6 +57,7 @@ namespace OpenSim.Framework.Servers.HttpServer { if(m_running) return; + m_running = true; m_workerPool = new ObjectJobEngine(PoolWorkerJob, "PollServiceWorker", 4000, m_WorkerThreadCount); @@ -86,12 +85,11 @@ namespace OpenSim.Framework.Servers.HttpServer private void CheckRetries() { - PollServiceHttpRequest preq; while (m_running) { Thread.Sleep(100); Watchdog.UpdateThread(); - while (m_running && m_retryRequests.TryDequeue(out preq)) + while (m_running && m_retryRequests.TryDequeue(out PollServiceHttpRequest preq)) m_workerPool.Enqueue(preq); } } @@ -126,8 +124,7 @@ namespace OpenSim.Framework.Servers.HttpServer private void PoolWorkerJob(object o) { - PollServiceHttpRequest req = o as PollServiceHttpRequest; - if(req == null) + if (o is not PollServiceHttpRequest req) return; try { @@ -176,7 +173,7 @@ namespace OpenSim.Framework.Servers.HttpServer } catch (Exception e) { - m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); + m_log.Error($"Exception in poll service thread: {e}"); } } } diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs index 3dfe333e3a..b392d4e78d 100755 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs @@ -55,7 +55,7 @@ namespace OpenSim.Region.ClientStack.Linden public partial class EventQueueGetModule : IEventQueue, INonSharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private static string LogHeader = "[EVENT QUEUE GET MODULE]"; + private static readonly string LogHeader = "[EVENT QUEUE GET MODULE]"; private const int KEEPALIVE = 60; // this could be larger now, but viewers expect it on opensim // we need to go back to close before viwers, or we may lose data @@ -68,10 +68,10 @@ namespace OpenSim.Region.ClientStack.Linden protected Scene m_scene; - private Dictionary m_ids = new Dictionary(); + private readonly Dictionary m_ids = new(); - private Dictionary> queues = new Dictionary>(); - private Dictionary m_AvatarQueueUUIDMapping = new Dictionary(); + private readonly Dictionary> queues = new(); + private readonly Dictionary m_AvatarQueueUUIDMapping = new(); #region INonSharedRegionModule methods public virtual void Initialise(IConfigSource config) @@ -339,9 +339,9 @@ namespace OpenSim.Region.ClientStack.Linden /// Generate an Event Queue Get handler path for the given eqg uuid. /// /// - private string GenerateEqgCapPath(UUID eqgUuid) + private static string GenerateEqgCapPath(UUID eqgUuid) { - return string.Format("/CE/{0}", eqgUuid); + return $"/CE/{eqgUuid}"; } public void OnRegisterCaps(UUID agentID, Caps caps) @@ -349,16 +349,13 @@ namespace OpenSim.Region.ClientStack.Linden // Register an event queue for the client if (DebugLevel > 0) - m_log.DebugFormat( - "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}", - agentID, caps, m_scene.RegionInfo.RegionName); + m_log.Debug( + $"[EVENTQUEUE]: OnRegisterCaps: agentID {agentID} caps {caps} region {m_scene.Name}"); UUID eventQueueGetUUID; - Queue queue = null; - lock (queues) { - queues.TryGetValue(agentID, out queue); + queues.TryGetValue(agentID, out Queue queue); if (queue == null) { @@ -388,17 +385,16 @@ namespace OpenSim.Region.ClientStack.Linden lock (m_AvatarQueueUUIDMapping) { // Its reuse caps path not queues those are been reused already - if (m_AvatarQueueUUIDMapping.ContainsKey(agentID)) + if (m_AvatarQueueUUIDMapping.TryGetValue(agentID, out eventQueueGetUUID)) { m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!"); - eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID]; lock (m_ids) { // change to negative numbers so they are changed at end of sending first marker // old data on a queue may be sent on a response for a new caps // but at least will be sent with coerent IDs - if (m_ids.ContainsKey(agentID)) - m_ids[agentID] = -m_ids[agentID]; + if (m_ids.TryGetValue(agentID, out int previd)) + m_ids[agentID] = -previd; else { m_ids[agentID] = -Random.Shared.Next(30000000); @@ -411,8 +407,8 @@ namespace OpenSim.Region.ClientStack.Linden m_AvatarQueueUUIDMapping[agentID] = eventQueueGetUUID; lock (m_ids) { - if (m_ids.ContainsKey(agentID)) - m_ids[agentID]++; + if (m_ids.TryGetValue(agentID, out int previd)) + m_ids[agentID] = ++previd; else { m_ids.Add(agentID, Random.Shared.Next(30000000)); @@ -428,7 +424,7 @@ namespace OpenSim.Region.ClientStack.Linden new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, Drop, agentID, VIEWERKEEPALIVE)); } - public bool HasEvents(UUID requestID, UUID agentID) + public bool HasEvents(in UUID _, in UUID agentID) { Queue queue = GetQueue(agentID); if (queue != null) @@ -449,28 +445,27 @@ namespace OpenSim.Region.ClientStack.Linden /// Element containing message private void LogOutboundDebugMessage(OSD element, UUID agentId) { - if (element is OSDMap) + if (element is OSDMap ev) { - OSDMap ev = (OSDMap)element; m_log.Debug($"Eq OUT {ev["message"],-30} to {m_scene.GetScenePresence(agentId).Name,-20} {m_scene.Name,-20}"); } } - public void Drop(UUID requestID, UUID pAgentId) + public void Drop(in UUID requestID, in UUID pAgentId) { // do nothing, in last case http server will do it } - private readonly byte[] EventHeader = osUTF8.GetASCIIBytes("events"); + private static readonly byte[] EventHeader = osUTF8.GetASCIIBytes("events"); - public Hashtable GetEvents(UUID requestID, UUID pAgentId) + public Hashtable GetEvents(in UUID requestID, in UUID pAgentId) { if (DebugLevel >= 2) m_log.Warn($"POLLED FOR EQ MESSAGES BY {pAgentId} in {m_scene.Name}"); Queue queue = GetQueue(pAgentId); - if (queue == null) - return NoAgent(requestID, pAgentId); + if (queue is null) + return NoAgent(); byte[] element = null; List elements; @@ -500,7 +495,7 @@ namespace OpenSim.Region.ClientStack.Linden element = queue.Dequeue(); // add elements until a marker is found // so they get into a response - if (element == null) + if (element is null) break; if (DebugLevel > 0) @@ -513,7 +508,7 @@ namespace OpenSim.Region.ClientStack.Linden lock (m_ids) { - if (element == null && negativeID) + if (element is null && negativeID) { m_ids[pAgentId] = Random.Shared.Next(30000000); } @@ -534,7 +529,7 @@ namespace OpenSim.Region.ClientStack.Linden elements.Add(element); totalSize += element.Length; - Hashtable responsedata = new Hashtable + Hashtable responsedata = new() { ["int_response_code"] = 200, ["content_type"] = "application/xml" @@ -556,26 +551,20 @@ namespace OpenSim.Region.ClientStack.Linden return responsedata; } - public Hashtable NoEvents(UUID requestID, UUID agentID) + public Hashtable NoEvents(in UUID _, in UUID agentID) { - Hashtable responsedata = new Hashtable(); - Queue queue = GetQueue(agentID); - if (queue == null) + return new Hashtable() { - responsedata["int_response_code"] = (int)HttpStatusCode.NotFound; - return responsedata; - } - responsedata["int_response_code"] = (int)HttpStatusCode.BadGateway; - return responsedata; + ["int_response_code"] = GetQueue(agentID) == null ? (int)HttpStatusCode.NotFound : (int)HttpStatusCode.BadGateway + }; } - public Hashtable NoAgent(UUID requestID, UUID agentID) + public static Hashtable NoAgent() { - Hashtable responsedata = new Hashtable + return new Hashtable() { ["int_response_code"] = (int)HttpStatusCode.NotFound }; - return responsedata; } } } diff --git a/OpenSim/Region/ClientStack/Linden/Caps/FetchLibDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/FetchLibDescModule.cs index bfa90c8f62..ecb34c9975 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/FetchLibDescModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/FetchLibDescModule.cs @@ -190,13 +190,13 @@ namespace OpenSim.Region.ClientStack.Linden { m_module = module; - HasEvents = (requestID, y) => + HasEvents = delegate (in UUID requestID, in UUID _) { lock (responses) return responses.ContainsKey(requestID); }; - Drop = (requestID, y) => + Drop = delegate (in UUID requestID, in UUID _) { lock (responses) { @@ -206,7 +206,7 @@ namespace OpenSim.Region.ClientStack.Linden } }; - GetEvents = (requestID, y) => + GetEvents = delegate (in UUID requestID, in UUID _) { lock (responses) { @@ -221,7 +221,7 @@ namespace OpenSim.Region.ClientStack.Linden } }; - Request = (requestID, request) => + Request = delegate(in UUID requestID, OSHttpRequest request) { APollRequest reqinfo = new APollRequest(); reqinfo.thepoll = this; @@ -231,7 +231,7 @@ namespace OpenSim.Region.ClientStack.Linden return null; }; - NoEvents = (x, y) => + NoEvents = delegate (in UUID _, in UUID _) { Hashtable response = new Hashtable(); response["int_response_code"] = 500; diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs index 7a0915d040..fdd1cd1a76 100755 --- a/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs @@ -199,7 +199,7 @@ namespace OpenSim.Region.ClientStack.Linden m_scene = scene; m_hgassets = HGAssetSVC; - HasEvents = (requestID, agentID) => + HasEvents = delegate(in UUID requestID, in UUID _) { lock (responses) { @@ -207,7 +207,7 @@ namespace OpenSim.Region.ClientStack.Linden } }; - Drop = (requestID, y) => + Drop = delegate(in UUID requestID, in UUID _) { lock (responses) { @@ -217,47 +217,48 @@ namespace OpenSim.Region.ClientStack.Linden } }; - GetEvents = (requestID, y) => + GetEvents = delegate(in UUID requestID, in UUID _) { lock (responses) { - try + if(responses.Remove(requestID, out APollResponse apr)) { - OSHttpResponse response = responses[requestID].osresponse; + OSHttpResponse response = apr.osresponse; if (response.Priority < 0) response.Priority = 0; - Hashtable lixo = new Hashtable(1); - lixo["h"] = response; + Hashtable lixo = new() + { + ["h"] = response + }; return lixo; } - finally - { - responses.Remove(requestID); - } } + return new Hashtable(); }; - // x is request id, y is request data hashtable - Request = (requestID, request) => + + Request = delegate (in UUID requestID, OSHttpRequest request) { - APollRequest reqinfo = new APollRequest(); - reqinfo.thepoll = this; - reqinfo.reqID = requestID; - reqinfo.request = request; + APollRequest reqinfo = new() + { + thepoll = this, + reqID = requestID, + request = request + }; m_workerpool.Enqueue(reqinfo); return null; }; // this should never happen except possible on shutdown - NoEvents = (x, y) => + NoEvents = delegate (in UUID _, in UUID _) { /* - lock (requests) - { - Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString()); - requests.Remove(request); - } + lock (requests) + { + Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString()); + requests.Remove(request); + } */ Hashtable response = new Hashtable(); diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs index 25da0200a2..64fd2f64b8 100755 --- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs @@ -229,7 +229,7 @@ namespace OpenSim.Region.ClientStack.Linden private class PollServiceInventoryEventArgs : PollServiceEventArgs { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private Dictionary responses = new Dictionary(); private HashSet dropedResponses = new HashSet(); @@ -241,13 +241,13 @@ namespace OpenSim.Region.ClientStack.Linden { m_module = module; - HasEvents = (requestID, y) => + HasEvents = delegate (in UUID requestID, in UUID _) { lock (responses) return responses.ContainsKey(requestID); }; - Drop = (requestID, y) => + Drop = delegate (in UUID requestID, in UUID _) { lock (responses) { @@ -257,7 +257,7 @@ namespace OpenSim.Region.ClientStack.Linden } }; - GetEvents = (requestID, y) => + GetEvents = delegate (in UUID requestID, in UUID _) { lock (responses) { @@ -272,7 +272,7 @@ namespace OpenSim.Region.ClientStack.Linden } }; - Request = (requestID, request) => + Request = delegate (in UUID requestID, OSHttpRequest request) { APollRequest reqinfo = new APollRequest(); reqinfo.thepoll = this; @@ -282,7 +282,7 @@ namespace OpenSim.Region.ClientStack.Linden return null; }; - NoEvents = (x, y) => + NoEvents = delegate (in UUID _, in UUID _) { Hashtable response = new Hashtable(); response["int_response_code"] = 500; diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index 147cbe27e6..4e1aa3d954 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs @@ -537,7 +537,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp } } - protected Hashtable NoEvents(UUID requestID, UUID sessionID) + protected Hashtable NoEvents(in UUID requestID, in UUID sessionID) { Hashtable response = new Hashtable(); UrlData url; @@ -569,7 +569,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp return response; } - protected bool HasEvents(UUID requestID, UUID sessionID) + protected bool HasEvents(in UUID requestID, in UUID sessionID) { UrlData url=null; @@ -591,7 +591,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp } } - protected void Drop(UUID requestID, UUID sessionID) + protected void Drop(in UUID requestID, in UUID _) { UrlData url = null; lock (m_RequestMap) @@ -608,7 +608,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp } } - protected Hashtable GetEvents(UUID requestID, UUID sessionID) + protected Hashtable GetEvents(in UUID requestID, in UUID sessionID) { UrlData url = null; @@ -689,7 +689,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp return resp; } - public OSHttpResponse HttpRequestHandler(UUID requestID, OSHttpRequest request) + public OSHttpResponse HttpRequestHandler(in UUID requestID, OSHttpRequest request) { lock (request) { @@ -707,7 +707,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp string uri_tmp; string pathInfo; - int pos = uri.IndexOf("/", 45); // /lslhttp/uuid/ <- + int pos = uri.IndexOf('/', 45); // /lslhttp/uuid/ <- if (pos >= 45) { uri_tmp = uri.Substring(0, pos); diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 9889738399..0d2a0c05a7 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -6162,7 +6162,7 @@ namespace OpenSim.Region.Framework.Scenes goto case "sequence"; do { - index = Util.RandomClass.Next(spawnPoints.Length - 1); + index = Random.Shared.Next(spawnPoints.Length - 1); spawnPosition = spawnPoints[index].GetLocation(teleHubPosition, teleHubRotation); land = m_scene.LandChannel.GetLandObject(spawnPosition.X,spawnPosition.Y); diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs index b2962054c0..d9f5a22e20 100644 --- a/OpenSim/Services/GridService/HypergridLinker.cs +++ b/OpenSim/Services/GridService/HypergridLinker.cs @@ -163,7 +163,7 @@ namespace OpenSim.Services.GridService return null; } - private static IPEndPoint dummyIP = new IPEndPoint(0,0); + private static readonly IPEndPoint dummyIP = new IPEndPoint(0,0); private bool TryCreateLinkImpl(UUID scopeID, int xloc, int yloc, RegionURI rurl, UUID ownerID, out GridRegion regInfo) { m_log.InfoFormat("[HYPERGRID LINKER]: Link to {0} {1}, in <{2},{3}>", @@ -293,7 +293,7 @@ namespace OpenSim.Services.GridService private bool TryCreateLinkImpl(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason) { m_log.InfoFormat("[HYPERGRID LINKER]: Link to {0} {1}, in <{2},{3}>", - ((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI), + (serverURI ?? externalHostName + ":" + externalPort), remoteRegionName, Util.WorldToRegionLoc((uint)xloc), Util.WorldToRegionLoc((uint)yloc)); reason = string.Empty;