Cleans up some pragmas (#136)

This commit is contained in:
Kamron Batman 2020-05-14 01:52:42 -07:00 committed by GitHub
parent 32ac48657a
commit 739e77a973
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 149 deletions

View file

@ -122,12 +122,7 @@ namespace System.Buffers
block = new MemoryPoolBlock(this, slab, offset, _blockSize); block = new MemoryPoolBlock(this, slab, offset, _blockSize);
if (i != blockCount - 1) // last block if (i != blockCount - 1) // last block
{
#if BLOCK_LEASE_TRACKING
block.IsLeased = true;
#endif
Return(block); Return(block);
}
offset += _blockSize; offset += _blockSize;
} }

View file

@ -37,8 +37,6 @@ using Server.Network;
namespace Server namespace Server
{ {
public delegate void Slice();
public static class Core public static class Core
{ {
private static bool m_Crashed; private static bool m_Crashed;
@ -50,21 +48,16 @@ namespace Server
private static DateTime m_ProfileStart; private static DateTime m_ProfileStart;
private static TimeSpan m_ProfileTime; private static TimeSpan m_ProfileTime;
public static Slice Slice;
/* /*
* DateTime.Now and DateTime.UtcNow are based on actual system clock time. * DateTime.Now and DateTime.UtcNow are based on actual system clock time.
* The resolution is acceptable but large clock jumps are possible and cause issues. * The resolution is acceptable but large clock jumps are possible and cause issues.
* GetTickCount and GetTickCount64 have poor resolution. * GetTickCount and GetTickCount64 have poor resolution.
* GetTickCount64 is unavailable on Windows XP and Windows Server 2003.
* Stopwatch.GetTimestamp() (QueryPerformanceCounter) is high resolution, but * Stopwatch.GetTimestamp() (QueryPerformanceCounter) is high resolution, but
* somewhat expensive to call because of its difference to DateTime.Now, * somewhat expensive to call because of its difference to DateTime.Now,
* which is why Stopwatch has been used to verify HRT before calling GetTimestamp(), * which is why Stopwatch has been used to verify HRT before calling GetTimestamp(),
* enabling the usage of DateTime.UtcNow instead. * enabling the usage of DateTime.UtcNow instead.
*/ */
private static readonly bool m_HighRes = Stopwatch.IsHighResolution;
private static readonly double m_HighFrequency = 1000.0 / Stopwatch.Frequency; private static readonly double m_HighFrequency = 1000.0 / Stopwatch.Frequency;
private static readonly double m_LowFrequency = 1000.0 / TimeSpan.TicksPerSecond; private static readonly double m_LowFrequency = 1000.0 / TimeSpan.TicksPerSecond;
@ -107,8 +100,6 @@ namespace Server
} }
} }
public static bool Debug { get; private set; }
internal static bool HaltOnWarning { get; private set; } internal static bool HaltOnWarning { get; private set; }
public static Assembly Assembly { get; set; } public static Assembly Assembly { get; set; }
@ -118,19 +109,12 @@ namespace Server
public static Thread Thread { get; private set; } public static Thread Thread { get; private set; }
public static bool UsingHighResolutionTiming => m_HighRes && !Unix;
public static long TickCount => (long)Ticks; public static long TickCount => (long)Ticks;
public static double Ticks public static double Ticks =>
{ Stopwatch.IsHighResolution
get ? Stopwatch.GetTimestamp() * m_HighFrequency
{ : DateTime.UtcNow.Ticks * m_LowFrequency;
if (m_HighRes && !Unix) return Stopwatch.GetTimestamp() * m_HighFrequency;
return DateTime.UtcNow.Ticks * m_LowFrequency;
}
}
public static bool MultiProcessor { get; private set; } public static bool MultiProcessor { get; private set; }
@ -177,9 +161,6 @@ namespace Server
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
if (Debug)
Utility.Separate(sb, "-debug", " ");
if (m_Profiling) if (m_Profiling)
Utility.Separate(sb, "-profile", " "); Utility.Separate(sb, "-profile", " ");
@ -316,9 +297,7 @@ namespace Server
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
foreach (var a in args) foreach (var a in args)
if (Insensitive.Equals(a, "-debug")) if (Insensitive.Equals(a, "-profile"))
Debug = true;
else if (Insensitive.Equals(a, "-profile"))
Profiling = true; Profiling = true;
else if (Insensitive.Equals(a, "-haltonwarning")) else if (Insensitive.Equals(a, "-haltonwarning"))
HaltOnWarning = true; HaltOnWarning = true;
@ -376,7 +355,7 @@ namespace Server
Console.WriteLine("Core: Server garbage collection mode enabled"); Console.WriteLine("Core: Server garbage collection mode enabled");
Console.WriteLine("Core: High resolution timing ({0})", Console.WriteLine("Core: High resolution timing ({0})",
UsingHighResolutionTiming ? "Supported" : "Unsupported"); Stopwatch.IsHighResolution ? "Supported" : "Unsupported");
Console.WriteLine("SecureRandomImpl: {0} ({1})", SecureRandomImpl.Name, Console.WriteLine("SecureRandomImpl: {0} ({1})", SecureRandomImpl.Name,
SecureRandomImpl.IsHardwareRNG ? "Hardware" : "Software"); SecureRandomImpl.IsHardwareRNG ? "Hardware" : "Software");
@ -439,8 +418,6 @@ namespace Server
NetState.ProcessDisposedQueue(); NetState.ProcessDisposedQueue();
Slice?.Invoke();
if (sample++ % sampleInterval != 0) if (sample++ % sampleInterval != 0)
continue; continue;
@ -562,106 +539,4 @@ namespace Server
public static bool EJ => Expansion >= Expansion.EJ; public static bool EJ => Expansion >= Expansion.EJ;
} }
public class FileLogger : TextWriter
{
public const string DateFormat = "[MMMM dd hh:mm:ss.f tt]: ";
private bool m_NewLine;
public FileLogger(string file, bool append = false)
{
FileName = file;
using (
var writer =
new StreamWriter(
new FileStream(FileName, append ? FileMode.Append : FileMode.Create, FileAccess.Write,
FileShare.Read)))
{
writer.WriteLine(">>>Logging started on {0}.", DateTime.UtcNow.ToString("f"));
// f = Tuesday, April 10, 2001 3:51 PM
}
m_NewLine = true;
}
public string FileName { get; }
public override Encoding Encoding => Encoding.Default;
public override void Write(char ch)
{
using var writer = new StreamWriter(new FileStream(FileName, FileMode.Append, FileAccess.Write, FileShare.Read));
if (m_NewLine)
{
writer.Write(DateTime.UtcNow.ToString(DateFormat));
m_NewLine = false;
}
writer.Write(ch);
}
public override void Write(string str)
{
using var writer =
new StreamWriter(new FileStream(FileName, FileMode.Append, FileAccess.Write, FileShare.Read));
if (m_NewLine)
{
writer.Write(DateTime.UtcNow.ToString(DateFormat));
m_NewLine = false;
}
writer.Write(str);
}
public override void WriteLine(string line)
{
using var writer =
new StreamWriter(new FileStream(FileName, FileMode.Append, FileAccess.Write, FileShare.Read));
if (m_NewLine) writer.Write(DateTime.UtcNow.ToString(DateFormat));
writer.WriteLine(line);
m_NewLine = true;
}
}
public class MultiTextWriter : TextWriter
{
private readonly List<TextWriter> m_Streams;
public MultiTextWriter(params TextWriter[] streams)
{
m_Streams = new List<TextWriter>(streams);
if (m_Streams.Count < 0) throw new ArgumentException("You must specify at least one stream.");
}
public override Encoding Encoding => Encoding.Default;
public void Add(TextWriter tw)
{
m_Streams.Add(tw);
}
public void Remove(TextWriter tw)
{
m_Streams.Remove(tw);
}
public override void Write(char ch)
{
foreach (var t in m_Streams) t.Write(ch);
}
public override void WriteLine(string line)
{
foreach (var t in m_Streams) t.WriteLine(line);
}
public override void WriteLine(string line, params object[] args)
{
WriteLine(string.Format(line, args));
}
}
} }

View file

@ -544,9 +544,6 @@ namespace Server.Network
public static void TraceException(Exception ex) public static void TraceException(Exception ex)
{ {
if (!Core.Debug)
return;
try try
{ {
using var op = new StreamWriter("network-errors.log", true); using var op = new StreamWriter("network-errors.log", true);

View file

@ -18,12 +18,11 @@
* *
***************************************************************************/ ***************************************************************************/
using System;
using System.IO; using System.IO;
#if !MONO #if WINDOWS
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles; using Microsoft.Win32.SafeHandles;
#endif #endif
namespace Server namespace Server
@ -37,12 +36,12 @@ namespace Server
public static int Concurrency { get; set; } = 1; public static int Concurrency { get; set; } = 1;
#if WINDOWS
public static bool Unbuffered { get; set; } = true; public static bool Unbuffered { get; set; } = true;
#endif
public static bool AreSynchronous => Concurrency < 1; public static bool AreSynchronous => Concurrency < 1;
public static bool AreAsynchronous => Concurrency > 0;
public static FileStream OpenSequentialStream(string path, FileMode mode, FileAccess access, FileShare share) public static FileStream OpenSequentialStream(string path, FileMode mode, FileAccess access, FileShare share)
{ {
var options = FileOptions.SequentialScan; var options = FileOptions.SequentialScan;
@ -50,7 +49,7 @@ namespace Server
if (Concurrency > 0) if (Concurrency > 0)
options |= FileOptions.Asynchronous; options |= FileOptions.Asynchronous;
#if MONO #if !WINDOWS
return new FileStream( path, mode, access, share, BufferSize, options ); return new FileStream( path, mode, access, share, BufferSize, options );
#else #else
if (Unbuffered) if (Unbuffered)
@ -67,7 +66,7 @@ namespace Server
#endif #endif
} }
#if !MONO #if WINDOWS
private class UnbufferedFileStream : FileStream private class UnbufferedFileStream : FileStream
{ {
private readonly SafeFileHandle fileHandle; private readonly SafeFileHandle fileHandle;
@ -94,7 +93,7 @@ namespace Server
} }
#endif #endif
#if !MONO #if WINDOWS
private const FileOptions NoBuffering = (FileOptions)0x20000000; private const FileOptions NoBuffering = (FileOptions)0x20000000;
internal static class UnsafeNativeMethods internal static class UnsafeNativeMethods

View file

@ -318,8 +318,6 @@ namespace Server.Commands
*/ */
public static bool DontLink(Type type) public static bool DontLink(Type type)
{ {
// MONO: type.Namespace is null/empty for generic arguments
if (type.Name == "T" || string.IsNullOrEmpty(type.Namespace) || m_Namespaces == null) if (type.Name == "T" || string.IsNullOrEmpty(type.Namespace) || m_Namespaces == null)
return true; return true;