misc clr nagging/housekeeping
This commit is contained in:
parent
edf716f3cc
commit
75817400fc
10 changed files with 141 additions and 106 deletions
|
|
@ -98,7 +98,7 @@ namespace Server
|
|||
m_Patch = pat;
|
||||
m_Type = type;
|
||||
|
||||
m_SourceString = ToString();
|
||||
m_SourceString = _ToStringImpl();
|
||||
}
|
||||
|
||||
public static bool operator == ( ClientVersion l, ClientVersion r )
|
||||
|
|
@ -153,36 +153,41 @@ namespace Server
|
|||
&& m_Type == v.m_Type;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
private string _ToStringImpl()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder( 16 );
|
||||
StringBuilder builder = new StringBuilder(16);
|
||||
|
||||
builder.Append( m_Major );
|
||||
builder.Append( '.' );
|
||||
builder.Append( m_Minor );
|
||||
builder.Append( '.' );
|
||||
builder.Append( m_Revision );
|
||||
builder.Append(m_Major);
|
||||
builder.Append('.');
|
||||
builder.Append(m_Minor);
|
||||
builder.Append('.');
|
||||
builder.Append(m_Revision);
|
||||
|
||||
if( m_Major <= 5 && m_Minor <= 0 && m_Revision <= 6 ) //Anything before 5.0.7
|
||||
if (m_Major <= 5 && m_Minor <= 0 && m_Revision <= 6) //Anything before 5.0.7
|
||||
{
|
||||
if( m_Patch > 0 )
|
||||
builder.Append( (char)('a' + (m_Patch - 1)) );
|
||||
if (m_Patch > 0)
|
||||
builder.Append((char)('a' + (m_Patch - 1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append( '.' );
|
||||
builder.Append( m_Patch );
|
||||
builder.Append('.');
|
||||
builder.Append(m_Patch);
|
||||
}
|
||||
|
||||
if ( m_Type != ClientType.Regular )
|
||||
if (m_Type != ClientType.Regular)
|
||||
{
|
||||
builder.Append( ' ' );
|
||||
builder.Append( m_Type.ToString() );
|
||||
builder.Append(' ');
|
||||
builder.Append(m_Type.ToString());
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _ToStringImpl();
|
||||
}
|
||||
|
||||
public ClientVersion( string fmt )
|
||||
{
|
||||
m_SourceString = fmt;
|
||||
|
|
|
|||
|
|
@ -796,7 +796,7 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public class FastWalkEventArgs
|
||||
public class FastWalkEventArgs : EventArgs
|
||||
{
|
||||
private NetState m_State;
|
||||
private bool m_Blocked;
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
private enum ConsoleEventType
|
||||
internal enum ConsoleEventType
|
||||
{
|
||||
CTRL_C_EVENT,
|
||||
CTRL_BREAK_EVENT,
|
||||
|
|
@ -365,18 +365,20 @@ namespace Server
|
|||
CTRL_SHUTDOWN_EVENT
|
||||
}
|
||||
|
||||
private delegate bool ConsoleEventHandler( ConsoleEventType type );
|
||||
private static ConsoleEventHandler m_ConsoleEventHandler;
|
||||
internal delegate bool ConsoleEventHandler( ConsoleEventType type );
|
||||
internal static ConsoleEventHandler m_ConsoleEventHandler;
|
||||
|
||||
[DllImport( "Kernel32" )]
|
||||
private static extern bool SetConsoleCtrlHandler( ConsoleEventHandler callback, bool add );
|
||||
internal class UnsafeNativeMethods {
|
||||
[DllImport("Kernel32")]
|
||||
internal static extern bool SetConsoleCtrlHandler(ConsoleEventHandler callback, bool add);
|
||||
}
|
||||
|
||||
private static bool OnConsoleEvent( ConsoleEventType type )
|
||||
{
|
||||
if( World.Saving || ( m_Service && type == ConsoleEventType.CTRL_LOGOFF_EVENT ) )
|
||||
return true;
|
||||
|
||||
Kill(); //Kill -> HandleClosed will hadnle waiting for the completion of flushign to disk
|
||||
Kill(); //Kill -> HandleClosed will handle waiting for the completion of flushing to disk
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -530,7 +532,7 @@ namespace Server
|
|||
}
|
||||
else {
|
||||
m_ConsoleEventHandler = new ConsoleEventHandler( OnConsoleEvent );
|
||||
SetConsoleCtrlHandler( m_ConsoleEventHandler, true );
|
||||
UnsafeNativeMethods.SetConsoleCtrlHandler( m_ConsoleEventHandler, true );
|
||||
}
|
||||
|
||||
if ( GCSettings.IsServerGC )
|
||||
|
|
|
|||
|
|
@ -475,6 +475,7 @@ namespace Server
|
|||
}
|
||||
#endregion
|
||||
|
||||
[Serializable]
|
||||
public class MobileNotConnectedException : Exception
|
||||
{
|
||||
public MobileNotConnectedException( Mobile source, string message )
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace Server {
|
||||
public static class NativeReader {
|
||||
|
|
@ -43,26 +44,35 @@ namespace Server {
|
|||
}
|
||||
|
||||
public sealed class NativeReaderWin32 : INativeReader {
|
||||
[DllImport( "kernel32" )]
|
||||
private unsafe static extern int _lread( IntPtr hFile, void *lpBuffer, int wBytes );
|
||||
internal class UnsafeNativeMethods {
|
||||
/*[DllImport("kernel32")]
|
||||
internal unsafe static extern int _lread(IntPtr hFile, void* lpBuffer, int wBytes);*/
|
||||
|
||||
[DllImport("kernel32")]
|
||||
internal unsafe static extern bool ReadFile(IntPtr hFile, void* lpBuffer, uint nNumberOfBytesToRead, ref uint lpNumberOfBytesRead, NativeOverlapped* lpOverlapped);
|
||||
}
|
||||
|
||||
public NativeReaderWin32() {
|
||||
}
|
||||
|
||||
public unsafe void Read( IntPtr ptr, void *buffer, int length ) {
|
||||
_lread( ptr, buffer, length );
|
||||
//UnsafeNativeMethods._lread( ptr, buffer, length );
|
||||
uint lpNumberOfBytesRead = 0;
|
||||
UnsafeNativeMethods.ReadFile(ptr, buffer, (uint)length, ref lpNumberOfBytesRead, null);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NativeReaderUnix : INativeReader {
|
||||
[DllImport( "libc" )]
|
||||
private unsafe static extern int read( IntPtr ptr, void *buffer, int length );
|
||||
internal class UnsafeNativeMethods {
|
||||
[DllImport("libc")]
|
||||
internal unsafe static extern int read(IntPtr ptr, void* buffer, int length);
|
||||
}
|
||||
|
||||
public NativeReaderUnix() {
|
||||
}
|
||||
|
||||
public unsafe void Read( IntPtr ptr, void *buffer, int length ) {
|
||||
read( ptr, buffer, length );
|
||||
UnsafeNativeMethods.read( ptr, buffer, length );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -227,149 +227,157 @@ namespace Server.Network {
|
|||
}
|
||||
|
||||
public sealed class Compressor32 : ICompressor {
|
||||
[DllImport( "zlib32" )]
|
||||
private static extern string zlibVersion();
|
||||
internal class SafeNativeMethods {
|
||||
[DllImport( "zlib32" )]
|
||||
internal static extern string zlibVersion();
|
||||
|
||||
[DllImport( "zlib32" )]
|
||||
private static extern ZLibError compress( byte[] dest, ref int destLength, byte[] source, int sourceLength );
|
||||
[DllImport( "zlib32" )]
|
||||
internal static extern ZLibError compress(byte[] dest, ref int destLength, byte[] source, int sourceLength);
|
||||
|
||||
[DllImport( "zlib32" )]
|
||||
private static extern ZLibError compress2( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality );
|
||||
[DllImport( "zlib32" )]
|
||||
internal static extern ZLibError compress2(byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality);
|
||||
|
||||
[DllImport( "zlib32" )]
|
||||
private static extern ZLibError uncompress( byte[] dest, ref int destLen, byte[] source, int sourceLen );
|
||||
[DllImport( "zlib32" )]
|
||||
internal static extern ZLibError uncompress(byte[] dest, ref int destLen, byte[] source, int sourceLen);
|
||||
}
|
||||
|
||||
public Compressor32() {
|
||||
}
|
||||
|
||||
public string Version {
|
||||
get {
|
||||
return zlibVersion();
|
||||
return SafeNativeMethods.zlibVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return compress( dest, ref destLength, source, sourceLength );
|
||||
return SafeNativeMethods.compress(dest, ref destLength, source, sourceLength);
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) {
|
||||
return compress2( dest, ref destLength, source, sourceLength, quality );
|
||||
return SafeNativeMethods.compress2(dest, ref destLength, source, sourceLength, quality);
|
||||
}
|
||||
|
||||
public ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return uncompress( dest, ref destLength, source, sourceLength );
|
||||
return SafeNativeMethods.uncompress(dest, ref destLength, source, sourceLength);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Compressor64 : ICompressor {
|
||||
[DllImport( "zlib64" )]
|
||||
private static extern string zlibVersion();
|
||||
internal class SafeNativeMethods {
|
||||
[DllImport("zlib64")]
|
||||
internal static extern string zlibVersion();
|
||||
|
||||
[DllImport( "zlib64" )]
|
||||
private static extern ZLibError compress( byte[] dest, ref int destLength, byte[] source, int sourceLength );
|
||||
[DllImport("zlib64")]
|
||||
internal static extern ZLibError compress(byte[] dest, ref int destLength, byte[] source, int sourceLength);
|
||||
|
||||
[DllImport( "zlib64" )]
|
||||
private static extern ZLibError compress2( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality );
|
||||
[DllImport("zlib64")]
|
||||
internal static extern ZLibError compress2(byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality);
|
||||
|
||||
[DllImport( "zlib64" )]
|
||||
private static extern ZLibError uncompress( byte[] dest, ref int destLen, byte[] source, int sourceLen );
|
||||
[DllImport("zlib64")]
|
||||
internal static extern ZLibError uncompress(byte[] dest, ref int destLen, byte[] source, int sourceLen);
|
||||
}
|
||||
|
||||
public Compressor64() {
|
||||
}
|
||||
|
||||
public string Version {
|
||||
get {
|
||||
return zlibVersion();
|
||||
return SafeNativeMethods.zlibVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return compress( dest, ref destLength, source, sourceLength );
|
||||
return SafeNativeMethods.compress(dest, ref destLength, source, sourceLength);
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) {
|
||||
return compress2( dest, ref destLength, source, sourceLength, quality );
|
||||
return SafeNativeMethods.compress2(dest, ref destLength, source, sourceLength, quality);
|
||||
}
|
||||
|
||||
public ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return uncompress( dest, ref destLength, source, sourceLength );
|
||||
return SafeNativeMethods.uncompress(dest, ref destLength, source, sourceLength);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CompressorUnix32 : ICompressor {
|
||||
[DllImport( "libz" )]
|
||||
private static extern string zlibVersion();
|
||||
internal class SafeNativeMethods {
|
||||
[DllImport("libz")]
|
||||
internal static extern string zlibVersion();
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError compress( byte[] dest, ref int destLength, byte[] source, int sourceLength );
|
||||
[DllImport("libz")]
|
||||
internal static extern ZLibError compress(byte[] dest, ref int destLength, byte[] source, int sourceLength);
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError compress2( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality );
|
||||
[DllImport("libz")]
|
||||
internal static extern ZLibError compress2(byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality);
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError uncompress( byte[] dest, ref int destLen, byte[] source, int sourceLen );
|
||||
[DllImport("libz")]
|
||||
internal static extern ZLibError uncompress(byte[] dest, ref int destLen, byte[] source, int sourceLen);
|
||||
}
|
||||
|
||||
public CompressorUnix32() {
|
||||
}
|
||||
|
||||
public string Version {
|
||||
get {
|
||||
return zlibVersion();
|
||||
return SafeNativeMethods.zlibVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return compress( dest, ref destLength, source, sourceLength );
|
||||
return SafeNativeMethods.compress(dest, ref destLength, source, sourceLength);
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) {
|
||||
return compress2( dest, ref destLength, source, sourceLength, quality );
|
||||
return SafeNativeMethods.compress2(dest, ref destLength, source, sourceLength, quality);
|
||||
}
|
||||
|
||||
public ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return uncompress( dest, ref destLength, source, sourceLength );
|
||||
return SafeNativeMethods.uncompress(dest, ref destLength, source, sourceLength);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CompressorUnix64 : ICompressor {
|
||||
[DllImport( "libz" )]
|
||||
private static extern string zlibVersion();
|
||||
internal class SafeNativeMethods {
|
||||
[DllImport("libz")]
|
||||
internal static extern string zlibVersion();
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError compress( byte[] dest, ref ulong destLength, byte[] source, int sourceLength );
|
||||
[DllImport("libz")]
|
||||
internal static extern ZLibError compress(byte[] dest, ref ulong destLength, byte[] source, int sourceLength);
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError compress2( byte[] dest, ref ulong destLength, byte[] source, int sourceLength, ZLibQuality quality );
|
||||
[DllImport("libz")]
|
||||
internal static extern ZLibError compress2(byte[] dest, ref ulong destLength, byte[] source, int sourceLength, ZLibQuality quality);
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError uncompress( byte[] dest, ref ulong destLen, byte[] source, int sourceLen );
|
||||
[DllImport("libz")]
|
||||
internal static extern ZLibError uncompress(byte[] dest, ref ulong destLen, byte[] source, int sourceLen);
|
||||
}
|
||||
|
||||
public CompressorUnix64() {
|
||||
}
|
||||
|
||||
public string Version {
|
||||
get {
|
||||
return zlibVersion();
|
||||
return SafeNativeMethods.zlibVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
ZLibError z = compress( dest, ref destLengthLong, source, sourceLength );
|
||||
ZLibError z = SafeNativeMethods.compress(dest, ref destLengthLong, source, sourceLength);
|
||||
destLength = (int)destLengthLong;
|
||||
return z;
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) {
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
ZLibError z = compress2( dest, ref destLengthLong, source, sourceLength, quality );
|
||||
ZLibError z = SafeNativeMethods.compress2(dest, ref destLengthLong, source, sourceLength, quality);
|
||||
destLength = (int)destLengthLong;
|
||||
return z;
|
||||
}
|
||||
|
||||
public ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
ZLibError z = uncompress( dest, ref destLengthLong, source, sourceLength );
|
||||
ZLibError z = SafeNativeMethods.uncompress(dest, ref destLengthLong, source, sourceLength);
|
||||
destLength = (int)destLengthLong;
|
||||
return z;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,10 @@ namespace Server {
|
|||
#if !MONO
|
||||
private const FileOptions NoBuffering = ( FileOptions ) 0x20000000;
|
||||
|
||||
[DllImport( "Kernel32", CharSet = CharSet.Auto, SetLastError = true )]
|
||||
private static extern SafeFileHandle CreateFile( string lpFileName, int dwDesiredAccess, FileShare dwShareMode, IntPtr securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile );
|
||||
internal static class UnsafeNativeMethods {
|
||||
[DllImport("Kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, IntPtr securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);
|
||||
}
|
||||
#endif
|
||||
|
||||
private static int bufferSize = 1 * MB;
|
||||
|
|
@ -101,7 +103,7 @@ namespace Server {
|
|||
return new FileStream( path, mode, access, share, bufferSize, options );
|
||||
}
|
||||
|
||||
SafeFileHandle fileHandle = CreateFile( path, (int) access, share, IntPtr.Zero, mode, (int) options, IntPtr.Zero );
|
||||
SafeFileHandle fileHandle = UnsafeNativeMethods.CreateFile(path, (int)access, share, IntPtr.Zero, mode, (int)options, IntPtr.Zero);
|
||||
|
||||
if ( fileHandle.IsInvalid ) {
|
||||
throw new IOException();
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ namespace Server {
|
|||
private int _Index = 0;
|
||||
|
||||
private object _sync = new object();
|
||||
private object _syncB = new object();
|
||||
|
||||
public CSPRandom() {
|
||||
_CSP.GetBytes(_Working);
|
||||
|
|
@ -127,7 +128,7 @@ namespace Server {
|
|||
if (_Index + c < BUFFER_SIZE)
|
||||
return;
|
||||
|
||||
lock (_Buffer) {
|
||||
lock (_syncB) {
|
||||
byte[] b = _Working;
|
||||
_Working = _Buffer;
|
||||
_Buffer = b;
|
||||
|
|
@ -138,7 +139,7 @@ namespace Server {
|
|||
}
|
||||
|
||||
private void Fill(object o) {
|
||||
lock (_Buffer)
|
||||
lock (_syncB)
|
||||
lock (_CSP)
|
||||
_CSP.GetBytes(_Buffer);
|
||||
}
|
||||
|
|
@ -214,11 +215,13 @@ namespace Server {
|
|||
}
|
||||
|
||||
public sealed class RDRand32 : IRandomImpl, IHardwareRNG {
|
||||
[DllImport("rdrand32")]
|
||||
private static extern RDRandError rdrand_32(ref uint rand, bool retry);
|
||||
internal class SafeNativeMethods {
|
||||
[DllImport("rdrand32")]
|
||||
internal static extern RDRandError rdrand_32(ref uint rand, bool retry);
|
||||
|
||||
[DllImport("rdrand32")]
|
||||
private static extern RDRandError rdrand_get_bytes(int n, byte[] buffer);
|
||||
[DllImport("rdrand32")]
|
||||
internal static extern RDRandError rdrand_get_bytes(int n, byte[] buffer);
|
||||
}
|
||||
|
||||
private static int BUFFER_SIZE = 0x10000;
|
||||
private static int LARGE_REQUEST = 0x40;
|
||||
|
|
@ -229,15 +232,16 @@ namespace Server {
|
|||
private int _Index = 0;
|
||||
|
||||
private object _sync = new object();
|
||||
private object _syncB = new object();
|
||||
|
||||
public RDRand32() {
|
||||
rdrand_get_bytes(BUFFER_SIZE, _Working);
|
||||
SafeNativeMethods.rdrand_get_bytes(BUFFER_SIZE, _Working);
|
||||
ThreadPool.QueueUserWorkItem(new WaitCallback(Fill));
|
||||
}
|
||||
|
||||
public bool IsSupported() {
|
||||
uint r = 0;
|
||||
return rdrand_32(ref r, true) == RDRandError.Success;
|
||||
return SafeNativeMethods.rdrand_32(ref r, true) == RDRandError.Success;
|
||||
}
|
||||
|
||||
private void CheckSwap(int c) {
|
||||
|
|
@ -245,7 +249,7 @@ namespace Server {
|
|||
if (_Index + c < BUFFER_SIZE)
|
||||
return;
|
||||
|
||||
lock (_Buffer) {
|
||||
lock (_syncB) {
|
||||
byte[] b = _Working;
|
||||
_Working = _Buffer;
|
||||
_Buffer = b;
|
||||
|
|
@ -256,8 +260,8 @@ namespace Server {
|
|||
}
|
||||
|
||||
private void Fill(object o) {
|
||||
lock (_Buffer)
|
||||
rdrand_get_bytes(BUFFER_SIZE, _Buffer);
|
||||
lock (_syncB)
|
||||
SafeNativeMethods.rdrand_get_bytes(BUFFER_SIZE, _Buffer);
|
||||
}
|
||||
|
||||
private void _GetBytes(byte[] b) {
|
||||
|
|
@ -299,7 +303,7 @@ namespace Server {
|
|||
int c = b.Length;
|
||||
|
||||
if (c >= LARGE_REQUEST) {
|
||||
rdrand_get_bytes(c, b);
|
||||
SafeNativeMethods.rdrand_get_bytes(c, b);
|
||||
return;
|
||||
}
|
||||
_GetBytes(b);
|
||||
|
|
@ -330,11 +334,13 @@ namespace Server {
|
|||
}
|
||||
|
||||
public sealed class RDRand64 : IRandomImpl, IHardwareRNG {
|
||||
[DllImport("rdrand64")]
|
||||
private static extern RDRandError rdrand_64(ref ulong rand, bool retry);
|
||||
internal class SafeNativeMethods {
|
||||
[DllImport("rdrand64")]
|
||||
internal static extern RDRandError rdrand_64(ref ulong rand, bool retry);
|
||||
|
||||
[DllImport("rdrand64")]
|
||||
private static extern RDRandError rdrand_get_bytes(int n, byte[] buffer);
|
||||
[DllImport("rdrand64")]
|
||||
internal static extern RDRandError rdrand_get_bytes(int n, byte[] buffer);
|
||||
}
|
||||
|
||||
private static int BUFFER_SIZE = 0x10000;
|
||||
private static int LARGE_REQUEST = 0x40;
|
||||
|
|
@ -345,15 +351,16 @@ namespace Server {
|
|||
private int _Index = 0;
|
||||
|
||||
private object _sync = new object();
|
||||
private object _syncB = new object();
|
||||
|
||||
public RDRand64() {
|
||||
rdrand_get_bytes(BUFFER_SIZE, _Working);
|
||||
SafeNativeMethods.rdrand_get_bytes(BUFFER_SIZE, _Working);
|
||||
ThreadPool.QueueUserWorkItem(new WaitCallback(Fill));
|
||||
}
|
||||
|
||||
public bool IsSupported() {
|
||||
ulong r = 0;
|
||||
return rdrand_64(ref r, true) == RDRandError.Success;
|
||||
return SafeNativeMethods.rdrand_64(ref r, true) == RDRandError.Success;
|
||||
}
|
||||
|
||||
private void CheckSwap(int c) {
|
||||
|
|
@ -361,7 +368,7 @@ namespace Server {
|
|||
if (_Index + c < BUFFER_SIZE)
|
||||
return;
|
||||
|
||||
lock (_Buffer) {
|
||||
lock (_syncB) {
|
||||
byte[] b = _Working;
|
||||
_Working = _Buffer;
|
||||
_Buffer = b;
|
||||
|
|
@ -372,8 +379,8 @@ namespace Server {
|
|||
}
|
||||
|
||||
private void Fill(object o) {
|
||||
lock (_Buffer)
|
||||
rdrand_get_bytes(BUFFER_SIZE, _Buffer);
|
||||
lock (_syncB)
|
||||
SafeNativeMethods.rdrand_get_bytes(BUFFER_SIZE, _Buffer);
|
||||
}
|
||||
|
||||
private void _GetBytes(byte[] b) {
|
||||
|
|
@ -415,7 +422,7 @@ namespace Server {
|
|||
int c = b.Length;
|
||||
|
||||
if (c >= LARGE_REQUEST) {
|
||||
rdrand_get_bytes(c, b);
|
||||
SafeNativeMethods.rdrand_get_bytes(c, b);
|
||||
return;
|
||||
}
|
||||
_GetBytes(b);
|
||||
|
|
|
|||
|
|
@ -462,7 +462,7 @@ namespace Server
|
|||
Utility.PushColor( ConsoleColor.DarkYellow );
|
||||
|
||||
foreach( CompilerError e in list )
|
||||
Console.WriteLine( " {0}: Line {1}: {3}", e.ErrorNumber, e.Line, e.Column, e.ErrorText );
|
||||
Console.WriteLine( " {0}: Line {1}: {2}", e.ErrorNumber, e.Line, e.ErrorText );
|
||||
|
||||
Utility.PopColor();
|
||||
}
|
||||
|
|
@ -487,7 +487,7 @@ namespace Server
|
|||
Utility.PushColor( ConsoleColor.DarkRed );
|
||||
|
||||
foreach( CompilerError e in list )
|
||||
Console.WriteLine( " {0}: Line {1}: {3}", e.ErrorNumber, e.Line, e.Column, e.ErrorText );
|
||||
Console.WriteLine( " {0}: Line {1}: {2}", e.ErrorNumber, e.Line, e.ErrorText );
|
||||
|
||||
Utility.PopColor();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -410,7 +410,7 @@ namespace Server
|
|||
get{ return true; }
|
||||
}
|
||||
|
||||
public virtual void RegCreation()
|
||||
public void RegCreation()
|
||||
{
|
||||
TimerProfile prof = GetProfile();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue