Commit 9180b523 authored by Nick Craver's avatar Nick Craver

Cleanup NETSTANDARD1_5 #if defs

Same order where possible and eliminated the Browsable attribute diffrence with a shim instead.
parent 87960ea3
#if NETSTANDARD1_5
using System;
namespace StackExchange.Redis
{
/// <summary>
/// Strictly for compat and less #if defs on netstandard1.5
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = false)]
internal class BrowsableAttribute : Attribute
{
public BrowsableAttribute(bool _) { }
}
}
#endif
\ No newline at end of file
...@@ -4,19 +4,19 @@ internal static class VolatileWrapper ...@@ -4,19 +4,19 @@ internal static class VolatileWrapper
{ {
public static int Read(ref int location) public static int Read(ref int location)
{ {
#if !NETSTANDARD1_5 #if NETSTANDARD1_5
return System.Threading.Thread.VolatileRead(ref location);
#else
return System.Threading.Volatile.Read(ref location); return System.Threading.Volatile.Read(ref location);
#else
return System.Threading.Thread.VolatileRead(ref location);
#endif #endif
} }
public static void Write(ref int address, int value) public static void Write(ref int address, int value)
{ {
#if !NETSTANDARD1_5 #if NETSTANDARD1_5
System.Threading.Thread.VolatileWrite(ref address, value);
#else
System.Threading.Volatile.Write(ref address, value); System.Threading.Volatile.Write(ref address, value);
#else
System.Threading.Thread.VolatileWrite(ref address, value);
#endif #endif
} }
} }
......
...@@ -145,10 +145,8 @@ public static string TryNormalize(string value) ...@@ -145,10 +145,8 @@ public static string TryNormalize(string value)
/// Indicates whether the connection should be encrypted /// Indicates whether the connection should be encrypted
/// </summary> /// </summary>
[Obsolete("Please use .Ssl instead of .UseSsl"), [Obsolete("Please use .Ssl instead of .UseSsl"),
#if !NETSTANDARD1_5 Browsable(false),
Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
#endif
EditorBrowsable(EditorBrowsableState.Never)]
public bool UseSsl { get { return Ssl; } set { Ssl = value; } } public bool UseSsl { get { return Ssl; } set { Ssl = value; } }
/// <summary> /// <summary>
......
...@@ -32,9 +32,7 @@ public HashEntry(RedisValue name, RedisValue value) ...@@ -32,9 +32,7 @@ public HashEntry(RedisValue name, RedisValue value)
/// <summary> /// <summary>
/// The name of the hash field /// The name of the hash field
/// </summary> /// </summary>
#if !NETSTANDARD1_5
[Browsable(false)] [Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Please use Name", false)] [EditorBrowsable(EditorBrowsableState.Never), Obsolete("Please use Name", false)]
public RedisValue Key { get { return name; } } public RedisValue Key { get { return name; } }
......
...@@ -639,7 +639,19 @@ unsafe void WriteRaw(Stream stream, string value, int encodedLength) ...@@ -639,7 +639,19 @@ unsafe void WriteRaw(Stream stream, string value, int encodedLength)
} }
else else
{ {
#if !NETSTANDARD1_5 #if NETSTANDARD1_5
int charsRemaining = value.Length, charOffset = 0, bytesWritten;
var valueCharArray = value.ToCharArray();
while (charsRemaining > Scratch_CharsPerBlock)
{
bytesWritten = outEncoder.GetBytes(valueCharArray, charOffset, Scratch_CharsPerBlock, outScratch, 0, false);
stream.Write(outScratch, 0, bytesWritten);
charOffset += Scratch_CharsPerBlock;
charsRemaining -= Scratch_CharsPerBlock;
}
bytesWritten = outEncoder.GetBytes(valueCharArray, charOffset, charsRemaining, outScratch, 0, true);
if (bytesWritten != 0) stream.Write(outScratch, 0, bytesWritten);
#else
fixed (char* c = value) fixed (char* c = value)
fixed (byte* b = outScratch) fixed (byte* b = outScratch)
{ {
...@@ -654,18 +666,6 @@ unsafe void WriteRaw(Stream stream, string value, int encodedLength) ...@@ -654,18 +666,6 @@ unsafe void WriteRaw(Stream stream, string value, int encodedLength)
bytesWritten = outEncoder.GetBytes(c + charOffset, charsRemaining, b, ScratchSize, true); bytesWritten = outEncoder.GetBytes(c + charOffset, charsRemaining, b, ScratchSize, true);
if (bytesWritten != 0) stream.Write(outScratch, 0, bytesWritten); if (bytesWritten != 0) stream.Write(outScratch, 0, bytesWritten);
} }
#else
int charsRemaining = value.Length, charOffset = 0, bytesWritten;
var valueCharArray = value.ToCharArray();
while (charsRemaining > Scratch_CharsPerBlock)
{
bytesWritten = outEncoder.GetBytes(valueCharArray, charOffset, Scratch_CharsPerBlock, outScratch, 0, false);
stream.Write(outScratch, 0, bytesWritten);
charOffset += Scratch_CharsPerBlock;
charsRemaining -= Scratch_CharsPerBlock;
}
bytesWritten = outEncoder.GetBytes(valueCharArray, charOffset, charsRemaining, outScratch, 0, true);
if (bytesWritten != 0) stream.Write(outScratch, 0, bytesWritten);
#endif #endif
} }
} }
......
...@@ -301,14 +301,14 @@ public int CompareTo(RedisValue other) ...@@ -301,14 +301,14 @@ public int CompareTo(RedisValue other)
if (otherType == CompareType.Double) return thisDouble.CompareTo(otherDouble); if (otherType == CompareType.Double) return thisDouble.CompareTo(otherDouble);
} }
// otherwise, compare as strings // otherwise, compare as strings
#if !NETSTANDARD1_5 #if NETSTANDARD1_5
return StringComparer.InvariantCulture.Compare((string)this, (string)other);
#else
var compareInfo = System.Globalization.CultureInfo.InvariantCulture.CompareInfo; var compareInfo = System.Globalization.CultureInfo.InvariantCulture.CompareInfo;
return compareInfo.Compare((string)this, (string)other, System.Globalization.CompareOptions.Ordinal); return compareInfo.Compare((string)this, (string)other, System.Globalization.CompareOptions.Ordinal);
#else
return StringComparer.InvariantCulture.Compare((string)this, (string)other);
#endif #endif
} }
catch(Exception ex) catch (Exception ex)
{ {
ConnectionMultiplexer.TraceWithoutContext(ex.Message); ConnectionMultiplexer.TraceWithoutContext(ex.Message);
} }
......
...@@ -313,10 +313,10 @@ static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref Loc ...@@ -313,10 +313,10 @@ static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref Loc
LocalBuilder redisKeyLoc = null; LocalBuilder redisKeyLoc = null;
var loc = il.DeclareLocal(t); var loc = il.DeclareLocal(t);
il.Emit(OpCodes.Ldarg_0); // object il.Emit(OpCodes.Ldarg_0); // object
#if !NETSTANDARD1_5 #if NETSTANDARD1_5
if (t.IsValueType)
#else
if (t.GetTypeInfo().IsValueType) if (t.GetTypeInfo().IsValueType)
#else
if (t.IsValueType)
#endif #endif
{ {
il.Emit(OpCodes.Unbox_Any, t); // T il.Emit(OpCodes.Unbox_Any, t); // T
...@@ -348,10 +348,10 @@ static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref Loc ...@@ -348,10 +348,10 @@ static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref Loc
{ {
il.Emit(OpCodes.Dup); // RedisKey[] RedisKey[] il.Emit(OpCodes.Dup); // RedisKey[] RedisKey[]
il.Emit(OpCodes.Ldc_I4, i); // RedisKey[] RedisKey[] int il.Emit(OpCodes.Ldc_I4, i); // RedisKey[] RedisKey[] int
#if !NETSTANDARD1_5 #if NETSTANDARD1_5
if (t.IsValueType)
#else
if (t.GetTypeInfo().IsValueType) if (t.GetTypeInfo().IsValueType)
#else
if (t.IsValueType)
#endif #endif
{ {
il.Emit(OpCodes.Ldloca, loc); // RedisKey[] RedisKey[] int T* il.Emit(OpCodes.Ldloca, loc); // RedisKey[] RedisKey[] int T*
...@@ -380,10 +380,10 @@ static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref Loc ...@@ -380,10 +380,10 @@ static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref Loc
{ {
il.Emit(OpCodes.Dup); // RedisKey[] RedisValue[] RedisValue[] il.Emit(OpCodes.Dup); // RedisKey[] RedisValue[] RedisValue[]
il.Emit(OpCodes.Ldc_I4, i); // RedisKey[] RedisValue[] RedisValue[] int il.Emit(OpCodes.Ldc_I4, i); // RedisKey[] RedisValue[] RedisValue[] int
#if !NETSTANDARD1_5 #if NETSTANDARD1_5
if (t.IsValueType)
#else
if (t.GetTypeInfo().IsValueType) if (t.GetTypeInfo().IsValueType)
#else
if (t.IsValueType)
#endif #endif
{ {
il.Emit(OpCodes.Ldloca, loc); // RedisKey[] RedisValue[] RedisValue[] int T* il.Emit(OpCodes.Ldloca, loc); // RedisKey[] RedisValue[] RedisValue[] int T*
......
...@@ -136,11 +136,11 @@ public SocketManager(string name, bool useHighPrioritySocketThreads) ...@@ -136,11 +136,11 @@ public SocketManager(string name, bool useHighPrioritySocketThreads)
// we need a dedicated writer, because when under heavy ambient load // we need a dedicated writer, because when under heavy ambient load
// (a busy asp.net site, for example), workers are not reliable enough // (a busy asp.net site, for example), workers are not reliable enough
#if !NETSTANDARD1_5 #if NETSTANDARD1_5
Thread dedicatedWriter = new Thread(writeAllQueues);
#else
Thread dedicatedWriter = new Thread(writeAllQueues, 32 * 1024); // don't need a huge stack; Thread dedicatedWriter = new Thread(writeAllQueues, 32 * 1024); // don't need a huge stack;
dedicatedWriter.Priority = useHighPrioritySocketThreads ? ThreadPriority.AboveNormal : ThreadPriority.Normal; dedicatedWriter.Priority = useHighPrioritySocketThreads ? ThreadPriority.AboveNormal : ThreadPriority.Normal;
#else
Thread dedicatedWriter = new Thread(writeAllQueues);
#endif #endif
dedicatedWriter.Name = name + ":Write"; dedicatedWriter.Name = name + ":Write";
dedicatedWriter.IsBackground = true; // should not keep process alive dedicatedWriter.IsBackground = true; // should not keep process alive
...@@ -254,19 +254,7 @@ internal void SetFastLoopbackOption(Socket socket) ...@@ -254,19 +254,7 @@ internal void SetFastLoopbackOption(Socket socket)
// or will be subject to WFP filtering. // or will be subject to WFP filtering.
const int SIO_LOOPBACK_FAST_PATH = -1744830448; const int SIO_LOOPBACK_FAST_PATH = -1744830448;
#if !NETSTANDARD1_5 #if NETSTANDARD1_5
// windows only
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
// Win8/Server2012+ only
var osVersion = Environment.OSVersion.Version;
if (osVersion.Major > 6 || osVersion.Major == 6 && osVersion.Minor >= 2)
{
byte[] optionInValue = BitConverter.GetBytes(1);
socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null);
}
}
#else
try try
{ {
// Ioctl is not supported on other platforms at the moment // Ioctl is not supported on other platforms at the moment
...@@ -276,9 +264,7 @@ internal void SetFastLoopbackOption(Socket socket) ...@@ -276,9 +264,7 @@ internal void SetFastLoopbackOption(Socket socket)
socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null); socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null);
} }
} }
catch (SocketException) catch (SocketException) { }
{
}
catch (PlatformNotSupportedException) catch (PlatformNotSupportedException)
{ {
// Fix for https://github.com/StackExchange/StackExchange.Redis/issues/582 // Fix for https://github.com/StackExchange/StackExchange.Redis/issues/582
...@@ -286,6 +272,18 @@ internal void SetFastLoopbackOption(Socket socket) ...@@ -286,6 +272,18 @@ internal void SetFastLoopbackOption(Socket socket)
// care if the platform check fails because this is for a Windows // care if the platform check fails because this is for a Windows
// optimization, and checking the platform will not fail on Windows. // optimization, and checking the platform will not fail on Windows.
} }
#else
// windows only
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
// Win8/Server2012+ only
var osVersion = Environment.OSVersion.Version;
if (osVersion.Major > 6 || osVersion.Major == 6 && osVersion.Minor >= 2)
{
byte[] optionInValue = BitConverter.GetBytes(1);
socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null);
}
}
#endif #endif
} }
......
...@@ -37,18 +37,14 @@ public SortedSetEntry(RedisValue element, double score) ...@@ -37,18 +37,14 @@ public SortedSetEntry(RedisValue element, double score)
/// <summary> /// <summary>
/// The score against the element /// The score against the element
/// </summary> /// </summary>
#if !NETSTANDARD1_5
[Browsable(false)] [Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Please use Score", false)] [EditorBrowsable(EditorBrowsableState.Never), Obsolete("Please use Score", false)]
public double Value { get { return score; } } public double Value { get { return score; } }
/// <summary> /// <summary>
/// The unique element stored in the sorted set /// The unique element stored in the sorted set
/// </summary> /// </summary>
#if !NETSTANDARD1_5
[Browsable(false)] [Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Please use Element", false)] [EditorBrowsable(EditorBrowsableState.Never), Obsolete("Please use Element", false)]
public RedisValue Key { get { return element; } } public RedisValue Key { get { return element; } }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment