Commit 4212ddeb authored by Nick Craver's avatar Nick Craver

Mono support...trying to...

parent a56779c1
...@@ -194,13 +194,7 @@ internal void OnErrorMessage(EndPoint endpoint, string message) ...@@ -194,13 +194,7 @@ internal void OnErrorMessage(EndPoint endpoint, string message)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
private static void Write<T>(ZipArchive zip, string name, Task task, Action<T, StreamWriter> callback) private static void Write<T>(ZipArchive zip, string name, Task task, Action<T, StreamWriter> callback)
{ {
var entry = zip.CreateEntry(name, var entry = zip.CreateEntry(name, PlatformHelper.GetCompressionLevel(nameof(CompressionLevel.Optimal)));
#if __MonoCS__
CompressionLevel.Fastest
#else
CompressionLevel.Optimal
#endif
);
using (var stream = entry.Open()) using (var stream = entry.Open())
using (var writer = new StreamWriter(stream)) using (var writer = new StreamWriter(stream))
{ {
......
...@@ -741,9 +741,6 @@ SocketMode ISocketCallback.Connected(Stream stream, TextWriter log) ...@@ -741,9 +741,6 @@ SocketMode ISocketCallback.Connected(Stream stream, TextWriter log)
var ssl = new SslStream(stream, false, config.CertificateValidationCallback, var ssl = new SslStream(stream, false, config.CertificateValidationCallback,
config.CertificateSelectionCallback ?? GetAmbientCertificateCallback() config.CertificateSelectionCallback ?? GetAmbientCertificateCallback()
#if !__MonoCS__
, EncryptionPolicy.RequireEncryption
#endif
); );
try try
{ {
......
using System;
using System.IO;
using System.IO.Compression;
using System.Net.Security;
namespace StackExchange.Redis
{
internal class PlatformHelper
{
public static SocketMode DefaultSocketMode = IsMono && IsUnix ? SocketMode.Async : SocketMode.Poll;
public static bool IsMono { get; } = Type.GetType("Mono.Runtime") != null;
public static bool IsUnix { get; } = (int)Environment.OSVersion.Platform == 4
|| (int)Environment.OSVersion.Platform == 6
|| (int)Environment.OSVersion.Platform == 128;
/// <summary>
/// Gets the compression level from a string, avoiding a naming bug inside ancient mono versions.
/// </summary>
/// <remarks>
/// See: https://github.com/mono/mono/commit/714efcf7d1f9c9017b370af16bb3117179dd60e5
/// </remarks>
/// <param name="level">The level.</param>
/// <returns></returns>
public static CompressionLevel GetCompressionLevel(string level)
{
try
{
return (CompressionLevel)Enum.Parse(typeof(CompressionLevel), level);
}
catch (ArgumentException)
{
// Oops, ancient mono here.. let's tray again.
return (CompressionLevel)Enum.Parse(typeof(CompressionLevel), level.Replace(nameof(CompressionLevel.Optimal), "Optional"));
}
}
}
}
...@@ -10,7 +10,7 @@ namespace StackExchange.Redis ...@@ -10,7 +10,7 @@ namespace StackExchange.Redis
{ {
public partial class SocketManager public partial class SocketManager
{ {
internal const SocketMode DefaultSocketMode = SocketMode.Poll; internal static SocketMode DefaultSocketMode = PlatformHelper.DefaultSocketMode;
private static readonly IntPtr[] EmptyPointers = new IntPtr[0]; private static readonly IntPtr[] EmptyPointers = new IntPtr[0];
private static readonly WaitCallback HelpProcessItems = state => private static readonly WaitCallback HelpProcessItems = state =>
{ {
...@@ -429,4 +429,4 @@ internal void Pulse() ...@@ -429,4 +429,4 @@ internal void Pulse()
} }
} }
} }
#endif #endif
\ No newline at end of file
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