diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 480e32259c..3cf1e7abc9 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -169,12 +169,12 @@ namespace OpenSim.Framework
}
private static uint nextXferID = 5000;
- private static Random randomClass = new ThreadSafeRandom();
+ private static readonly Random randomClass = new ThreadSafeRandom();
// Get a list of invalid file characters (OS dependent)
- private static string regexInvalidFileChars = "[" + new String(Path.GetInvalidFileNameChars()) + "]";
- private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]";
- private static object XferLock = new object();
+ private static readonly string regexInvalidFileChars = "[" + new String(Path.GetInvalidFileNameChars()) + "]";
+ private static readonly string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]";
+ private static readonly object XferLock = new object();
///
/// Thread pool used for Util.FireAndForget if FireAndForgetMethod.SmartThreadPool is used
@@ -703,8 +703,10 @@ namespace OpenSim.Framework
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
- XmlTextWriter xtw = new XmlTextWriter(sw);
- xtw.Formatting = Formatting.Indented;
+ XmlTextWriter xtw = new XmlTextWriter(sw)
+ {
+ Formatting = Formatting.Indented
+ };
try
{
@@ -1316,8 +1318,7 @@ namespace OpenSim.Framework
if(String.IsNullOrWhiteSpace(dnsAddress))
return null;
- IPAddress ia = null;
- if(dnscache.TryGetValue(dnsAddress, out ia) && ia != null)
+ if(dnscache.TryGetValue(dnsAddress, out IPAddress ia) && ia != null)
{
dnscache.AddOrUpdate(dnsAddress, ia, 300);
return ia;
@@ -1384,9 +1385,8 @@ namespace OpenSim.Framework
{
if(String.IsNullOrWhiteSpace(hostname))
return null;
-
- IPAddress ia = null;
- if(dnscache.TryGetValue(hostname, out ia) && ia != null)
+
+ if(dnscache.TryGetValue(hostname, out IPAddress ia) && ia != null)
{
dnscache.AddOrUpdate(hostname, ia, 300);
return getEndPoint(ia, port);
@@ -1497,8 +1497,7 @@ namespace OpenSim.Framework
url = String.Empty;
assetID = String.Empty;
- UUID uuid;
- if (UUID.TryParse(id, out uuid))
+ if (UUID.TryParse(id, out UUID uuid))
{
assetID = uuid.ToString();
return false;
@@ -1507,25 +1506,11 @@ namespace OpenSim.Framework
if ((id.Length == 0) || (id[0] != 'h' && id[0] != 'H'))
return false;
- Uri assetUri;
- if (!Uri.TryCreate(id, UriKind.Absolute, out assetUri) || assetUri.Scheme != Uri.UriSchemeHttp)
+ if (!Uri.TryCreate(id, UriKind.Absolute, out Uri assetUri) || assetUri.Scheme != Uri.UriSchemeHttp)
return false;
- // Simian
- if (assetUri.Query != string.Empty)
- {
- NameValueCollection qscoll = HttpUtility.ParseQueryString(assetUri.Query);
- assetID = qscoll["id"];
- if (assetID != null)
- url = id.Replace(assetID, ""); // Malformed again, as simian expects
- else
- url = id; // !!! best effort
- }
- else // robust
- {
- url = "http://" + assetUri.Authority;
- assetID = assetUri.LocalPath.Trim(new char[] { '/' });
- }
+ url = "http://" + assetUri.Authority;
+ assetID = assetUri.LocalPath.Trim(new char[] { '/' });
if (!UUID.TryParse(assetID, out uuid))
return false;
@@ -1538,7 +1523,7 @@ namespace OpenSim.Framework
///
/// path
/// safe path
- public static string safePath(string path)
+ public static string SafePath(string path)
{
return Regex.Replace(path, regexInvalidPathChars, String.Empty);
}
@@ -1548,7 +1533,7 @@ namespace OpenSim.Framework
///
/// filename
/// safe filename
- public static string safeFileName(string filename)
+ public static string SafeFileName(string filename)
{
return Regex.Replace(filename, regexInvalidFileChars, String.Empty);
;
@@ -1600,7 +1585,7 @@ namespace OpenSim.Framework
return "./OpenSim.log";
}
- public static string statsLogFile()
+ public static string StatsLogFile()
{
foreach (IAppender appender in LogManager.GetRepository().GetAppenders())
{
@@ -2102,9 +2087,11 @@ namespace OpenSim.Framework
public static XmlRpcResponse CreateUnknownUserErrorResponse()
{
XmlRpcResponse response = new XmlRpcResponse();
- Hashtable responseData = new Hashtable();
- responseData["error_type"] = "unknown_user";
- responseData["error_desc"] = "The user requested is not in the database";
+ Hashtable responseData = new Hashtable()
+ {
+ ["error_type"] = "unknown_user",
+ ["error_desc"] = "The user requested is not in the database"
+ };
response.Value = responseData;
return response;
@@ -2172,11 +2159,8 @@ namespace OpenSim.Framework
public static void FakeParcelIDToGlobalPosition(UUID parcelID, out uint x, out uint y)
{
- ulong regionHandle;
- uint rx, ry;
-
- ParseFakeParcelID(parcelID, out regionHandle, out x, out y);
- Utils.LongToUInts(regionHandle, out rx, out ry);
+ ParseFakeParcelID(parcelID, out ulong regionHandle, out x, out y);
+ Utils.LongToUInts(regionHandle, out uint rx, out uint ry);
x += rx;
y += ry;
@@ -2837,11 +2821,13 @@ namespace OpenSim.Framework
return;
}
- STPStartInfo startInfo = new STPStartInfo();
- startInfo.ThreadPoolName = "Util";
- startInfo.IdleTimeout = 20000;
- startInfo.MaxWorkerThreads = maxThreads;
- startInfo.MinWorkerThreads = minThreads;
+ STPStartInfo startInfo = new STPStartInfo()
+ {
+ ThreadPoolName = "Util",
+ IdleTimeout = 20000,
+ MaxWorkerThreads = maxThreads,
+ MinWorkerThreads = minThreads
+ };
m_ThreadPool = new SmartThreadPool(startInfo);
m_threadPoolWatchdog = new Timer(ThreadPoolWatchdog, null, 0, 1000);
@@ -2877,7 +2863,7 @@ namespace OpenSim.Framework
{
public long ThreadFuncNum { get; set; }
public string StackTrace { get; set; }
- private string context;
+ private readonly string context;
public bool LogThread { get; set; }
public IWorkItemResult WorkItem { get; set; }
@@ -2948,7 +2934,6 @@ namespace OpenSim.Framework
private static long numQueuedThreadFuncs = 0;
private static long numRunningThreadFuncs = 0;
private static long numTotalThreadFuncsCalled = 0;
- private static Int32 threadFuncOverloadMode = 0;
public static long TotalQueuedFireAndForgetCalls { get { return numQueuedThreadFuncs; } }
public static long TotalRunningFireAndForgetCalls { get { return numRunningThreadFuncs; } }
@@ -2971,8 +2956,7 @@ namespace OpenSim.Framework
m_log.WarnFormat("Timeout in threadfunc {0} ({1}) {2}", t.ThreadFuncNum, t.Thread.Name, t.GetStackTrace());
t.Abort();
- ThreadInfo dummy;
- activeThreads.TryRemove(entry.Key, out dummy);
+ activeThreads.TryRemove(entry.Key, out ThreadInfo dummy);
// It's possible that the thread won't abort. To make sure the thread pool isn't
// depleted, increase the pool size.
@@ -2988,14 +2972,14 @@ namespace OpenSim.Framework
return new Dictionary(m_fireAndForgetCallsMade);
}
- private static Dictionary m_fireAndForgetCallsMade = new Dictionary();
+ private static readonly Dictionary m_fireAndForgetCallsMade = new Dictionary();
public static Dictionary GetFireAndForgetCallsInProgress()
{
return new Dictionary(m_fireAndForgetCallsInProgress);
}
- private static Dictionary m_fireAndForgetCallsInProgress = new Dictionary();
+ private static readonly Dictionary m_fireAndForgetCallsInProgress = new Dictionary();
public static void FireAndForget(System.Threading.WaitCallback callback)
{
@@ -3041,7 +3025,7 @@ namespace OpenSim.Framework
try
{
- if ((loggingEnabled || (threadFuncOverloadMode == 1)) && threadInfo.LogThread)
+ if (loggingEnabled && threadInfo.LogThread)
m_log.DebugFormat("Run threadfunc {0} (Queued {1}, Running {2})", threadFuncNum, numQueued1, numRunning1);
Culture.SetCurrentCulture();
@@ -3059,7 +3043,7 @@ namespace OpenSim.Framework
Interlocked.Decrement(ref numRunningThreadFuncs);
threadInfo.Ended();
activeThreads.TryRemove(threadFuncNum, out ThreadInfo dummy);
- if ((loggingEnabled || (threadFuncOverloadMode == 1)) && threadInfo.LogThread)
+ if (loggingEnabled && threadInfo.LogThread)
m_log.DebugFormat("Exit threadfunc {0} ({1})", threadFuncNum, FormatDuration(threadInfo.Elapsed()));
callback = null;
o = null;
@@ -3266,18 +3250,19 @@ namespace OpenSim.Framework
if (m_ThreadPool == null)
return null;
- STPInfo stpi = new STPInfo();
- stpi.Name = m_ThreadPool.Name;
- stpi.STPStartInfo = m_ThreadPool.STPStartInfo;
- stpi.IsIdle = m_ThreadPool.IsIdle;
- stpi.IsShuttingDown = m_ThreadPool.IsShuttingdown;
- stpi.MaxThreads = m_ThreadPool.MaxThreads;
- stpi.MinThreads = m_ThreadPool.MinThreads;
- stpi.InUseThreads = m_ThreadPool.InUseThreads;
- stpi.ActiveThreads = m_ThreadPool.ActiveThreads;
- stpi.WaitingCallbacks = m_ThreadPool.WaitingCallbacks;
- stpi.MaxConcurrentWorkItems = m_ThreadPool.Concurrency;
-
+ STPInfo stpi = new STPInfo()
+ {
+ Name = m_ThreadPool.Name,
+ STPStartInfo = m_ThreadPool.STPStartInfo,
+ IsIdle = m_ThreadPool.IsIdle,
+ IsShuttingDown = m_ThreadPool.IsShuttingdown,
+ MaxThreads = m_ThreadPool.MaxThreads,
+ MinThreads = m_ThreadPool.MinThreads,
+ InUseThreads = m_ThreadPool.InUseThreads,
+ ActiveThreads = m_ThreadPool.ActiveThreads,
+ WaitingCallbacks = m_ThreadPool.WaitingCallbacks,
+ MaxConcurrentWorkItems = m_ThreadPool.Concurrency
+ };
return stpi;
}
@@ -3524,7 +3509,6 @@ namespace OpenSim.Framework
public static UUID ReadUUID(XmlReader reader, string name)
{
- UUID id;
string idStr;
reader.ReadStartElement(name);
@@ -3535,7 +3519,8 @@ namespace OpenSim.Framework
idStr = reader.ReadElementString("UUID");
else // no leading tag
idStr = reader.ReadContentAsString();
- UUID.TryParse(idStr, out id);
+
+ UUID.TryParse(idStr, out UUID id);
reader.ReadEndElement();
return id;
diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs
index 3d12b41697..d2163e1895 100644
--- a/OpenSim/Region/Application/Application.cs
+++ b/OpenSim/Region/Application/Application.cs
@@ -77,12 +77,7 @@ namespace OpenSim
Culture.SetCurrentCulture();
Culture.SetDefaultCurrentCulture();
- if(Util.IsWindows())
- ServicePointManager.DefaultConnectionLimit = 32;
- else
- {
- ServicePointManager.DefaultConnectionLimit = 12;
- }
+ ServicePointManager.DefaultConnectionLimit = 64;
try { ServicePointManager.DnsRefreshTimeout = 5000; } catch { }
ServicePointManager.Expect100Continue = false;
@@ -127,14 +122,12 @@ namespace OpenSim
int iocpThreadsMin = 1000;
int iocpThreadsMax = 2000; // may need further adjustment to match other CLR
- int currentMinWorkerThreads, currentMinIocpThreads;
- System.Threading.ThreadPool.GetMinThreads(out currentMinWorkerThreads, out currentMinIocpThreads);
+ System.Threading.ThreadPool.GetMinThreads(out int currentMinWorkerThreads, out int currentMinIocpThreads);
m_log.InfoFormat(
"[OPENSIM MAIN]: Runtime gave us {0} min worker threads and {1} min IOCP threads",
currentMinWorkerThreads, currentMinIocpThreads);
- int workerThreads, iocpThreads;
- System.Threading.ThreadPool.GetMaxThreads(out workerThreads, out iocpThreads);
+ System.Threading.ThreadPool.GetMaxThreads(out int workerThreads, out int iocpThreads);
m_log.InfoFormat("[OPENSIM MAIN]: Runtime gave us {0} max worker threads and {1} max IOCP threads", workerThreads, iocpThreads);
if (workerThreads < workerThreadsMin)
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index 1f1dd8b6dd..1fb39d33b7 100755
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -114,8 +114,8 @@ namespace OpenSim
}
string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty);
- FireAndForgetMethod asyncCallMethod;
- if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse(asyncCallMethodStr, out asyncCallMethod))
+ if (!String.IsNullOrEmpty(asyncCallMethodStr) &&
+ Utils.EnumTryParse(asyncCallMethodStr, out FireAndForgetMethod asyncCallMethod))
Util.FireAndForgetMethod = asyncCallMethod;
stpMinThreads = startupConfig.GetInt("MinPoolThreads", 2 );
@@ -266,9 +266,11 @@ namespace OpenSim
// Start timer script (run a script every xx seconds)
if (m_timedScript != "disabled")
{
- m_scriptTimer = new System.Timers.Timer();
- m_scriptTimer.Enabled = true;
- m_scriptTimer.Interval = m_timeInterval*1000;
+ m_scriptTimer = new System.Timers.Timer()
+ {
+ Enabled = true,
+ Interval = m_timeInterval*1000,
+ };
m_scriptTimer.Elapsed += RunAutoTimerScript;
}
}
@@ -784,8 +786,7 @@ namespace OpenSim
regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source, regionName);
}
- Scene existingScene;
- if (SceneManager.TryGetScene(regInfo.RegionID, out existingScene))
+ if (SceneManager.TryGetScene(regInfo.RegionID, out Scene existingScene))
{
MainConsole.Instance.Output(
"ERROR: Cannot create region {0} with ID {1}, this ID is already assigned to region {2}",
@@ -795,8 +796,7 @@ namespace OpenSim
}
bool changed = PopulateRegionEstateInfo(regInfo);
- IScene scene;
- CreateRegion(regInfo, true, out scene);
+ CreateRegion(regInfo, true, out IScene scene);
if (changed)
m_estateDataService.StoreEstateSettings(regInfo.EstateSettings);
@@ -1279,13 +1279,11 @@ namespace OpenSim
protected void CreateEstateCommand(string module, string[] args)
{
string response = null;
- UUID userID;
-
if (args.Length == 2)
{
response = "No user specified.";
}
- else if (!UUID.TryParse(args[2], out userID))
+ else if (!UUID.TryParse(args[2], out UUID userID))
{
response = String.Format("{0} is not a valid UUID", args[2]);
}
@@ -1341,8 +1339,7 @@ namespace OpenSim
}
else
{
- int estateId;
- if (!int.TryParse(args[3], out estateId))
+ if (!int.TryParse(args[3], out int estateId))
{
response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
}
@@ -1363,8 +1360,7 @@ namespace OpenSim
if (args.Length == 5)
{
// attempt to get account by UUID
- UUID u;
- if (UUID.TryParse(s1, out u))
+ if (UUID.TryParse(s1, out UUID u))
{
account = scene.UserAccountService.GetUserAccount(scopeID, u);
if (account == null)
@@ -1414,8 +1410,7 @@ namespace OpenSim
}
else
{
- int estateId;
- if (!int.TryParse(args[3], out estateId))
+ if (!int.TryParse(args[3], out int estateId))
{
response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
}