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
{
public static int Read(ref int location)
{
#if !NETSTANDARD1_5
return System.Threading.Thread.VolatileRead(ref location);
#else
#if NETSTANDARD1_5
return System.Threading.Volatile.Read(ref location);
#else
return System.Threading.Thread.VolatileRead(ref location);
#endif
}
public static void Write(ref int address, int value)
{
#if !NETSTANDARD1_5
System.Threading.Thread.VolatileWrite(ref address, value);
#else
#if NETSTANDARD1_5
System.Threading.Volatile.Write(ref address, value);
#else
System.Threading.Thread.VolatileWrite(ref address, value);
#endif
}
}
......
......@@ -145,10 +145,8 @@ public static string TryNormalize(string value)
/// Indicates whether the connection should be encrypted
/// </summary>
[Obsolete("Please use .Ssl instead of .UseSsl"),
#if !NETSTANDARD1_5
Browsable(false),
#endif
EditorBrowsable(EditorBrowsableState.Never)]
Browsable(false),
EditorBrowsable(EditorBrowsableState.Never)]
public bool UseSsl { get { return Ssl; } set { Ssl = value; } }
/// <summary>
......
......@@ -32,9 +32,7 @@ public HashEntry(RedisValue name, RedisValue value)
/// <summary>
/// The name of the hash field
/// </summary>
#if !NETSTANDARD1_5
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Please use Name", false)]
public RedisValue Key { get { return name; } }
......
......@@ -639,7 +639,19 @@ unsafe void WriteRaw(Stream stream, string value, int encodedLength)
}
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 (byte* b = outScratch)
{
......@@ -654,18 +666,6 @@ unsafe void WriteRaw(Stream stream, string value, int encodedLength)
bytesWritten = outEncoder.GetBytes(c + charOffset, charsRemaining, b, ScratchSize, true);
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
}
}
......
......@@ -301,14 +301,14 @@ public int CompareTo(RedisValue other)
if (otherType == CompareType.Double) return thisDouble.CompareTo(otherDouble);
}
// otherwise, compare as strings
#if !NETSTANDARD1_5
return StringComparer.InvariantCulture.Compare((string)this, (string)other);
#else
#if NETSTANDARD1_5
var compareInfo = System.Globalization.CultureInfo.InvariantCulture.CompareInfo;
return compareInfo.Compare((string)this, (string)other, System.Globalization.CompareOptions.Ordinal);
#else
return StringComparer.InvariantCulture.Compare((string)this, (string)other);
#endif
}
catch(Exception ex)
catch (Exception ex)
{
ConnectionMultiplexer.TraceWithoutContext(ex.Message);
}
......
......@@ -313,10 +313,10 @@ static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref Loc
LocalBuilder redisKeyLoc = null;
var loc = il.DeclareLocal(t);
il.Emit(OpCodes.Ldarg_0); // object
#if !NETSTANDARD1_5
if (t.IsValueType)
#else
#if NETSTANDARD1_5
if (t.GetTypeInfo().IsValueType)
#else
if (t.IsValueType)
#endif
{
il.Emit(OpCodes.Unbox_Any, t); // T
......@@ -348,10 +348,10 @@ static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref Loc
{
il.Emit(OpCodes.Dup); // RedisKey[] RedisKey[]
il.Emit(OpCodes.Ldc_I4, i); // RedisKey[] RedisKey[] int
#if !NETSTANDARD1_5
if (t.IsValueType)
#else
#if NETSTANDARD1_5
if (t.GetTypeInfo().IsValueType)
#else
if (t.IsValueType)
#endif
{
il.Emit(OpCodes.Ldloca, loc); // RedisKey[] RedisKey[] int T*
......@@ -380,10 +380,10 @@ static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref Loc
{
il.Emit(OpCodes.Dup); // RedisKey[] RedisValue[] RedisValue[]
il.Emit(OpCodes.Ldc_I4, i); // RedisKey[] RedisValue[] RedisValue[] int
#if !NETSTANDARD1_5
if (t.IsValueType)
#else
#if NETSTANDARD1_5
if (t.GetTypeInfo().IsValueType)
#else
if (t.IsValueType)
#endif
{
il.Emit(OpCodes.Ldloca, loc); // RedisKey[] RedisValue[] RedisValue[] int T*
......
......@@ -136,11 +136,11 @@ public SocketManager(string name, bool useHighPrioritySocketThreads)
// we need a dedicated writer, because when under heavy ambient load
// (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;
dedicatedWriter.Priority = useHighPrioritySocketThreads ? ThreadPriority.AboveNormal : ThreadPriority.Normal;
#else
Thread dedicatedWriter = new Thread(writeAllQueues);
#endif
dedicatedWriter.Name = name + ":Write";
dedicatedWriter.IsBackground = true; // should not keep process alive
......@@ -254,19 +254,7 @@ internal void SetFastLoopbackOption(Socket socket)
// or will be subject to WFP filtering.
const int SIO_LOOPBACK_FAST_PATH = -1744830448;
#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
#if NETSTANDARD1_5
try
{
// Ioctl is not supported on other platforms at the moment
......@@ -276,9 +264,7 @@ internal void SetFastLoopbackOption(Socket socket)
socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null);
}
}
catch (SocketException)
{
}
catch (SocketException) { }
catch (PlatformNotSupportedException)
{
// Fix for https://github.com/StackExchange/StackExchange.Redis/issues/582
......@@ -286,6 +272,18 @@ internal void SetFastLoopbackOption(Socket socket)
// care if the platform check fails because this is for a 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
}
......
......@@ -37,18 +37,14 @@ public SortedSetEntry(RedisValue element, double score)
/// <summary>
/// The score against the element
/// </summary>
#if !NETSTANDARD1_5
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Please use Score", false)]
public double Value { get { return score; } }
/// <summary>
/// The unique element stored in the sorted set
/// </summary>
#if !NETSTANDARD1_5
[Browsable(false)]
#endif
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Please use Element", false)]
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