cosmetics

master
UbitUmarov 2020-07-15 19:13:22 +01:00
parent 6a27f3fb20
commit 402186844c
3 changed files with 69 additions and 96 deletions

View File

@ -169,12 +169,12 @@ namespace OpenSim.Framework
} }
private static uint nextXferID = 5000; 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) // Get a list of invalid file characters (OS dependent)
private static string regexInvalidFileChars = "[" + new String(Path.GetInvalidFileNameChars()) + "]"; private static readonly string regexInvalidFileChars = "[" + new String(Path.GetInvalidFileNameChars()) + "]";
private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]"; private static readonly string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]";
private static object XferLock = new object(); private static readonly object XferLock = new object();
/// <summary> /// <summary>
/// Thread pool used for Util.FireAndForget if FireAndForgetMethod.SmartThreadPool is used /// Thread pool used for Util.FireAndForget if FireAndForgetMethod.SmartThreadPool is used
@ -703,8 +703,10 @@ namespace OpenSim.Framework
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb); StringWriter sw = new StringWriter(sb);
XmlTextWriter xtw = new XmlTextWriter(sw); XmlTextWriter xtw = new XmlTextWriter(sw)
xtw.Formatting = Formatting.Indented; {
Formatting = Formatting.Indented
};
try try
{ {
@ -1316,8 +1318,7 @@ namespace OpenSim.Framework
if(String.IsNullOrWhiteSpace(dnsAddress)) if(String.IsNullOrWhiteSpace(dnsAddress))
return null; return null;
IPAddress ia = null; if(dnscache.TryGetValue(dnsAddress, out IPAddress ia) && ia != null)
if(dnscache.TryGetValue(dnsAddress, out ia) && ia != null)
{ {
dnscache.AddOrUpdate(dnsAddress, ia, 300); dnscache.AddOrUpdate(dnsAddress, ia, 300);
return ia; return ia;
@ -1385,8 +1386,7 @@ namespace OpenSim.Framework
if(String.IsNullOrWhiteSpace(hostname)) if(String.IsNullOrWhiteSpace(hostname))
return null; return null;
IPAddress ia = null; if(dnscache.TryGetValue(hostname, out IPAddress ia) && ia != null)
if(dnscache.TryGetValue(hostname, out ia) && ia != null)
{ {
dnscache.AddOrUpdate(hostname, ia, 300); dnscache.AddOrUpdate(hostname, ia, 300);
return getEndPoint(ia, port); return getEndPoint(ia, port);
@ -1497,8 +1497,7 @@ namespace OpenSim.Framework
url = String.Empty; url = String.Empty;
assetID = String.Empty; assetID = String.Empty;
UUID uuid; if (UUID.TryParse(id, out UUID uuid))
if (UUID.TryParse(id, out uuid))
{ {
assetID = uuid.ToString(); assetID = uuid.ToString();
return false; return false;
@ -1507,25 +1506,11 @@ namespace OpenSim.Framework
if ((id.Length == 0) || (id[0] != 'h' && id[0] != 'H')) if ((id.Length == 0) || (id[0] != 'h' && id[0] != 'H'))
return false; return false;
Uri assetUri; if (!Uri.TryCreate(id, UriKind.Absolute, out Uri assetUri) || assetUri.Scheme != Uri.UriSchemeHttp)
if (!Uri.TryCreate(id, UriKind.Absolute, out assetUri) || assetUri.Scheme != Uri.UriSchemeHttp)
return false; 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; url = "http://" + assetUri.Authority;
assetID = assetUri.LocalPath.Trim(new char[] { '/' }); assetID = assetUri.LocalPath.Trim(new char[] { '/' });
}
if (!UUID.TryParse(assetID, out uuid)) if (!UUID.TryParse(assetID, out uuid))
return false; return false;
@ -1538,7 +1523,7 @@ namespace OpenSim.Framework
/// </summary> /// </summary>
/// <param name="path">path</param> /// <param name="path">path</param>
/// <returns>safe path</returns> /// <returns>safe path</returns>
public static string safePath(string path) public static string SafePath(string path)
{ {
return Regex.Replace(path, regexInvalidPathChars, String.Empty); return Regex.Replace(path, regexInvalidPathChars, String.Empty);
} }
@ -1548,7 +1533,7 @@ namespace OpenSim.Framework
/// </summary> /// </summary>
/// <param name="path">filename</param> /// <param name="path">filename</param>
/// <returns>safe filename</returns> /// <returns>safe filename</returns>
public static string safeFileName(string filename) public static string SafeFileName(string filename)
{ {
return Regex.Replace(filename, regexInvalidFileChars, String.Empty); return Regex.Replace(filename, regexInvalidFileChars, String.Empty);
; ;
@ -1600,7 +1585,7 @@ namespace OpenSim.Framework
return "./OpenSim.log"; return "./OpenSim.log";
} }
public static string statsLogFile() public static string StatsLogFile()
{ {
foreach (IAppender appender in LogManager.GetRepository().GetAppenders()) foreach (IAppender appender in LogManager.GetRepository().GetAppenders())
{ {
@ -2102,9 +2087,11 @@ namespace OpenSim.Framework
public static XmlRpcResponse CreateUnknownUserErrorResponse() public static XmlRpcResponse CreateUnknownUserErrorResponse()
{ {
XmlRpcResponse response = new XmlRpcResponse(); XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable(); Hashtable responseData = new Hashtable()
responseData["error_type"] = "unknown_user"; {
responseData["error_desc"] = "The user requested is not in the database"; ["error_type"] = "unknown_user",
["error_desc"] = "The user requested is not in the database"
};
response.Value = responseData; response.Value = responseData;
return response; return response;
@ -2172,11 +2159,8 @@ namespace OpenSim.Framework
public static void FakeParcelIDToGlobalPosition(UUID parcelID, out uint x, out uint y) public static void FakeParcelIDToGlobalPosition(UUID parcelID, out uint x, out uint y)
{ {
ulong regionHandle; ParseFakeParcelID(parcelID, out ulong regionHandle, out x, out y);
uint rx, ry; Utils.LongToUInts(regionHandle, out uint rx, out uint ry);
ParseFakeParcelID(parcelID, out regionHandle, out x, out y);
Utils.LongToUInts(regionHandle, out rx, out ry);
x += rx; x += rx;
y += ry; y += ry;
@ -2837,11 +2821,13 @@ namespace OpenSim.Framework
return; return;
} }
STPStartInfo startInfo = new STPStartInfo(); STPStartInfo startInfo = new STPStartInfo()
startInfo.ThreadPoolName = "Util"; {
startInfo.IdleTimeout = 20000; ThreadPoolName = "Util",
startInfo.MaxWorkerThreads = maxThreads; IdleTimeout = 20000,
startInfo.MinWorkerThreads = minThreads; MaxWorkerThreads = maxThreads,
MinWorkerThreads = minThreads
};
m_ThreadPool = new SmartThreadPool(startInfo); m_ThreadPool = new SmartThreadPool(startInfo);
m_threadPoolWatchdog = new Timer(ThreadPoolWatchdog, null, 0, 1000); m_threadPoolWatchdog = new Timer(ThreadPoolWatchdog, null, 0, 1000);
@ -2877,7 +2863,7 @@ namespace OpenSim.Framework
{ {
public long ThreadFuncNum { get; set; } public long ThreadFuncNum { get; set; }
public string StackTrace { get; set; } public string StackTrace { get; set; }
private string context; private readonly string context;
public bool LogThread { get; set; } public bool LogThread { get; set; }
public IWorkItemResult WorkItem { get; set; } public IWorkItemResult WorkItem { get; set; }
@ -2948,7 +2934,6 @@ namespace OpenSim.Framework
private static long numQueuedThreadFuncs = 0; private static long numQueuedThreadFuncs = 0;
private static long numRunningThreadFuncs = 0; private static long numRunningThreadFuncs = 0;
private static long numTotalThreadFuncsCalled = 0; private static long numTotalThreadFuncsCalled = 0;
private static Int32 threadFuncOverloadMode = 0;
public static long TotalQueuedFireAndForgetCalls { get { return numQueuedThreadFuncs; } } public static long TotalQueuedFireAndForgetCalls { get { return numQueuedThreadFuncs; } }
public static long TotalRunningFireAndForgetCalls { get { return numRunningThreadFuncs; } } 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()); m_log.WarnFormat("Timeout in threadfunc {0} ({1}) {2}", t.ThreadFuncNum, t.Thread.Name, t.GetStackTrace());
t.Abort(); t.Abort();
ThreadInfo dummy; activeThreads.TryRemove(entry.Key, out ThreadInfo dummy);
activeThreads.TryRemove(entry.Key, out dummy);
// It's possible that the thread won't abort. To make sure the thread pool isn't // It's possible that the thread won't abort. To make sure the thread pool isn't
// depleted, increase the pool size. // depleted, increase the pool size.
@ -2988,14 +2972,14 @@ namespace OpenSim.Framework
return new Dictionary<string, int>(m_fireAndForgetCallsMade); return new Dictionary<string, int>(m_fireAndForgetCallsMade);
} }
private static Dictionary<string, int> m_fireAndForgetCallsMade = new Dictionary<string, int>(); private static readonly Dictionary<string, int> m_fireAndForgetCallsMade = new Dictionary<string, int>();
public static Dictionary<string, int> GetFireAndForgetCallsInProgress() public static Dictionary<string, int> GetFireAndForgetCallsInProgress()
{ {
return new Dictionary<string, int>(m_fireAndForgetCallsInProgress); return new Dictionary<string, int>(m_fireAndForgetCallsInProgress);
} }
private static Dictionary<string, int> m_fireAndForgetCallsInProgress = new Dictionary<string, int>(); private static readonly Dictionary<string, int> m_fireAndForgetCallsInProgress = new Dictionary<string, int>();
public static void FireAndForget(System.Threading.WaitCallback callback) public static void FireAndForget(System.Threading.WaitCallback callback)
{ {
@ -3041,7 +3025,7 @@ namespace OpenSim.Framework
try try
{ {
if ((loggingEnabled || (threadFuncOverloadMode == 1)) && threadInfo.LogThread) if (loggingEnabled && threadInfo.LogThread)
m_log.DebugFormat("Run threadfunc {0} (Queued {1}, Running {2})", threadFuncNum, numQueued1, numRunning1); m_log.DebugFormat("Run threadfunc {0} (Queued {1}, Running {2})", threadFuncNum, numQueued1, numRunning1);
Culture.SetCurrentCulture(); Culture.SetCurrentCulture();
@ -3059,7 +3043,7 @@ namespace OpenSim.Framework
Interlocked.Decrement(ref numRunningThreadFuncs); Interlocked.Decrement(ref numRunningThreadFuncs);
threadInfo.Ended(); threadInfo.Ended();
activeThreads.TryRemove(threadFuncNum, out ThreadInfo dummy); 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())); m_log.DebugFormat("Exit threadfunc {0} ({1})", threadFuncNum, FormatDuration(threadInfo.Elapsed()));
callback = null; callback = null;
o = null; o = null;
@ -3266,18 +3250,19 @@ namespace OpenSim.Framework
if (m_ThreadPool == null) if (m_ThreadPool == null)
return null; return null;
STPInfo stpi = new STPInfo(); STPInfo stpi = new STPInfo()
stpi.Name = m_ThreadPool.Name; {
stpi.STPStartInfo = m_ThreadPool.STPStartInfo; Name = m_ThreadPool.Name,
stpi.IsIdle = m_ThreadPool.IsIdle; STPStartInfo = m_ThreadPool.STPStartInfo,
stpi.IsShuttingDown = m_ThreadPool.IsShuttingdown; IsIdle = m_ThreadPool.IsIdle,
stpi.MaxThreads = m_ThreadPool.MaxThreads; IsShuttingDown = m_ThreadPool.IsShuttingdown,
stpi.MinThreads = m_ThreadPool.MinThreads; MaxThreads = m_ThreadPool.MaxThreads,
stpi.InUseThreads = m_ThreadPool.InUseThreads; MinThreads = m_ThreadPool.MinThreads,
stpi.ActiveThreads = m_ThreadPool.ActiveThreads; InUseThreads = m_ThreadPool.InUseThreads,
stpi.WaitingCallbacks = m_ThreadPool.WaitingCallbacks; ActiveThreads = m_ThreadPool.ActiveThreads,
stpi.MaxConcurrentWorkItems = m_ThreadPool.Concurrency; WaitingCallbacks = m_ThreadPool.WaitingCallbacks,
MaxConcurrentWorkItems = m_ThreadPool.Concurrency
};
return stpi; return stpi;
} }
@ -3524,7 +3509,6 @@ namespace OpenSim.Framework
public static UUID ReadUUID(XmlReader reader, string name) public static UUID ReadUUID(XmlReader reader, string name)
{ {
UUID id;
string idStr; string idStr;
reader.ReadStartElement(name); reader.ReadStartElement(name);
@ -3535,7 +3519,8 @@ namespace OpenSim.Framework
idStr = reader.ReadElementString("UUID"); idStr = reader.ReadElementString("UUID");
else // no leading tag else // no leading tag
idStr = reader.ReadContentAsString(); idStr = reader.ReadContentAsString();
UUID.TryParse(idStr, out id);
UUID.TryParse(idStr, out UUID id);
reader.ReadEndElement(); reader.ReadEndElement();
return id; return id;

View File

@ -77,12 +77,7 @@ namespace OpenSim
Culture.SetCurrentCulture(); Culture.SetCurrentCulture();
Culture.SetDefaultCurrentCulture(); Culture.SetDefaultCurrentCulture();
if(Util.IsWindows()) ServicePointManager.DefaultConnectionLimit = 64;
ServicePointManager.DefaultConnectionLimit = 32;
else
{
ServicePointManager.DefaultConnectionLimit = 12;
}
try { ServicePointManager.DnsRefreshTimeout = 5000; } catch { } try { ServicePointManager.DnsRefreshTimeout = 5000; } catch { }
ServicePointManager.Expect100Continue = false; ServicePointManager.Expect100Continue = false;
@ -127,14 +122,12 @@ namespace OpenSim
int iocpThreadsMin = 1000; int iocpThreadsMin = 1000;
int iocpThreadsMax = 2000; // may need further adjustment to match other CLR int iocpThreadsMax = 2000; // may need further adjustment to match other CLR
int currentMinWorkerThreads, currentMinIocpThreads; System.Threading.ThreadPool.GetMinThreads(out int currentMinWorkerThreads, out int currentMinIocpThreads);
System.Threading.ThreadPool.GetMinThreads(out currentMinWorkerThreads, out currentMinIocpThreads);
m_log.InfoFormat( m_log.InfoFormat(
"[OPENSIM MAIN]: Runtime gave us {0} min worker threads and {1} min IOCP threads", "[OPENSIM MAIN]: Runtime gave us {0} min worker threads and {1} min IOCP threads",
currentMinWorkerThreads, currentMinIocpThreads); currentMinWorkerThreads, currentMinIocpThreads);
int workerThreads, iocpThreads; System.Threading.ThreadPool.GetMaxThreads(out int workerThreads, out int iocpThreads);
System.Threading.ThreadPool.GetMaxThreads(out workerThreads, out iocpThreads);
m_log.InfoFormat("[OPENSIM MAIN]: Runtime gave us {0} max worker threads and {1} max IOCP threads", workerThreads, iocpThreads); m_log.InfoFormat("[OPENSIM MAIN]: Runtime gave us {0} max worker threads and {1} max IOCP threads", workerThreads, iocpThreads);
if (workerThreads < workerThreadsMin) if (workerThreads < workerThreadsMin)

View File

@ -114,8 +114,8 @@ namespace OpenSim
} }
string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty); string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty);
FireAndForgetMethod asyncCallMethod; if (!String.IsNullOrEmpty(asyncCallMethodStr) &&
if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod)) Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out FireAndForgetMethod asyncCallMethod))
Util.FireAndForgetMethod = asyncCallMethod; Util.FireAndForgetMethod = asyncCallMethod;
stpMinThreads = startupConfig.GetInt("MinPoolThreads", 2 ); stpMinThreads = startupConfig.GetInt("MinPoolThreads", 2 );
@ -266,9 +266,11 @@ namespace OpenSim
// Start timer script (run a script every xx seconds) // Start timer script (run a script every xx seconds)
if (m_timedScript != "disabled") if (m_timedScript != "disabled")
{ {
m_scriptTimer = new System.Timers.Timer(); m_scriptTimer = new System.Timers.Timer()
m_scriptTimer.Enabled = true; {
m_scriptTimer.Interval = m_timeInterval*1000; Enabled = true,
Interval = m_timeInterval*1000,
};
m_scriptTimer.Elapsed += RunAutoTimerScript; m_scriptTimer.Elapsed += RunAutoTimerScript;
} }
} }
@ -784,8 +786,7 @@ namespace OpenSim
regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source, regionName); regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source, regionName);
} }
Scene existingScene; if (SceneManager.TryGetScene(regInfo.RegionID, out Scene existingScene))
if (SceneManager.TryGetScene(regInfo.RegionID, out existingScene))
{ {
MainConsole.Instance.Output( MainConsole.Instance.Output(
"ERROR: Cannot create region {0} with ID {1}, this ID is already assigned to region {2}", "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); bool changed = PopulateRegionEstateInfo(regInfo);
IScene scene; CreateRegion(regInfo, true, out IScene scene);
CreateRegion(regInfo, true, out scene);
if (changed) if (changed)
m_estateDataService.StoreEstateSettings(regInfo.EstateSettings); m_estateDataService.StoreEstateSettings(regInfo.EstateSettings);
@ -1279,13 +1279,11 @@ namespace OpenSim
protected void CreateEstateCommand(string module, string[] args) protected void CreateEstateCommand(string module, string[] args)
{ {
string response = null; string response = null;
UUID userID;
if (args.Length == 2) if (args.Length == 2)
{ {
response = "No user specified."; 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]); response = String.Format("{0} is not a valid UUID", args[2]);
} }
@ -1341,8 +1339,7 @@ namespace OpenSim
} }
else else
{ {
int estateId; if (!int.TryParse(args[3], out int estateId))
if (!int.TryParse(args[3], out estateId))
{ {
response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]); response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
} }
@ -1363,8 +1360,7 @@ namespace OpenSim
if (args.Length == 5) if (args.Length == 5)
{ {
// attempt to get account by UUID // attempt to get account by UUID
UUID u; if (UUID.TryParse(s1, out UUID u))
if (UUID.TryParse(s1, out u))
{ {
account = scene.UserAccountService.GetUserAccount(scopeID, u); account = scene.UserAccountService.GetUserAccount(scopeID, u);
if (account == null) if (account == null)
@ -1414,8 +1410,7 @@ namespace OpenSim
} }
else else
{ {
int estateId; if (!int.TryParse(args[3], out int estateId))
if (!int.TryParse(args[3], out estateId))
{ {
response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]); response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
} }