Commit 5b5be771 authored by Nick Craver's avatar Nick Craver

Cleanup pass

parent e898ec45
...@@ -8,14 +8,15 @@ ...@@ -8,14 +8,15 @@
<PackageId>$(AssemblyName)</PackageId> <PackageId>$(AssemblyName)</PackageId>
<Authors>Stack Exchange, Inc.; marc.gravell</Authors> <Authors>Stack Exchange, Inc.; marc.gravell</Authors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CodeAnalysisRuleset>$(MSBuildThisFileDirectory)Shared.ruleset</CodeAnalysisRuleset>
<PackageReleaseNotes>https://stackexchange.github.io/StackExchange.Redis/ReleaseNotes</PackageReleaseNotes> <PackageReleaseNotes>https://stackexchange.github.io/StackExchange.Redis/ReleaseNotes</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/StackExchange/StackExchange.Redis/</PackageProjectUrl> <PackageProjectUrl>https://github.com/StackExchange/StackExchange.Redis/</PackageProjectUrl>
<PackageLicenseUrl>https://raw.github.com/StackExchange/StackExchange.Redis/master/LICENSE</PackageLicenseUrl> <PackageLicenseUrl>https://raw.github.com/StackExchange/StackExchange.Redis/master/LICENSE</PackageLicenseUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/StackExchange/StackExchange.Redis/</RepositoryUrl> <RepositoryUrl>https://github.com/StackExchange/StackExchange.Redis/</RepositoryUrl>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType> <DebugType>embedded</DebugType>
<DefaultLanguage>en-US</DefaultLanguage> <DefaultLanguage>en-US</DefaultLanguage>
...@@ -27,7 +28,7 @@ ...@@ -27,7 +28,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="2.1.23" PrivateAssets="all" /> <PackageReference Include="Nerdbank.GitVersioning" Version="2.1.23" PrivateAssets="all" />
<PackageReference Include="SourceLink.Create.GitHub" Version="2.8.2" PrivateAssets="All" /> <PackageReference Include="SourceLink.Create.GitHub" Version="2.8.2" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.8.2" /> <DotNetCliToolReference Include="dotnet-sourcelink" Version="2.8.2" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.8.2" /> <DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.8.2" />
</ItemGroup> </ItemGroup>
......
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for StackOverflow" Description="Code analysis rules for the StackOverflow solution." ToolsVersion="15.0">
<IncludeAll Action="Warning" />
<Rules AnalyzerId="Roslynator.CSharp.Analyzers" RuleNamespace="Roslynator.CSharp.Analyzers">
<Rule Id="RCS1057" Action="None" />
</Rules>
</RuleSet>
\ No newline at end of file
...@@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ...@@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.build.props = Directory.build.props Directory.build.props = Directory.build.props
global.json = global.json global.json = global.json
NuGet.Config = NuGet.Config NuGet.Config = NuGet.Config
Shared.ruleset = Shared.ruleset
version.json = version.json version.json = version.json
EndProjectSection EndProjectSection
EndProject EndProject
......
...@@ -38,7 +38,7 @@ internal sealed partial class PhysicalBridge : IDisposable ...@@ -38,7 +38,7 @@ internal sealed partial class PhysicalBridge : IDisposable
private int profileLogIndex; private int profileLogIndex;
private volatile bool reportNextFailure = true, reconfigureNextFailure = false; private volatile bool reportNextFailure = true, reconfigureNextFailure = false;
private volatile int state = (int)State.Disconnected; private volatile int state = (int)State.Disconnected;
public PhysicalBridge(ServerEndPoint serverEndPoint, ConnectionType type, int timeoutMilliseconds) public PhysicalBridge(ServerEndPoint serverEndPoint, ConnectionType type, int timeoutMilliseconds)
......
...@@ -54,6 +54,7 @@ internal partial interface ISocketCallback ...@@ -54,6 +54,7 @@ internal partial interface ISocketCallback
internal struct SocketToken internal struct SocketToken
{ {
internal readonly Socket Socket; internal readonly Socket Socket;
public SocketToken(Socket socket) public SocketToken(Socket socket)
{ {
Socket = socket; Socket = socket;
...@@ -130,10 +131,12 @@ internal static SocketManager Shared ...@@ -130,10 +131,12 @@ internal static SocketManager Shared
shared = new SocketManager("DefaultSocketManager", false, DEFAULT_MIN_THREADS, DEFAULT_MAX_THREADS * 2); shared = new SocketManager("DefaultSocketManager", false, DEFAULT_MIN_THREADS, DEFAULT_MAX_THREADS * 2);
if (Interlocked.CompareExchange(ref _shared, shared, null) == null) if (Interlocked.CompareExchange(ref _shared, shared, null) == null)
shared = null; shared = null;
} finally { shared?.Dispose(); } }
finally { shared?.Dispose(); }
return Interlocked.CompareExchange(ref _shared, null, null); return Interlocked.CompareExchange(ref _shared, null, null);
} }
} }
private static SocketManager _shared; private static SocketManager _shared;
/// <summary> /// <summary>
...@@ -142,21 +145,22 @@ internal static SocketManager Shared ...@@ -142,21 +145,22 @@ internal static SocketManager Shared
/// <param name="name">The name for this <see cref="SocketManager"/>.</param> /// <param name="name">The name for this <see cref="SocketManager"/>.</param>
/// <param name="useHighPrioritySocketThreads">Whether this <see cref="SocketManager"/> should use high priority sockets.</param> /// <param name="useHighPrioritySocketThreads">Whether this <see cref="SocketManager"/> should use high priority sockets.</param>
public SocketManager(string name, bool useHighPrioritySocketThreads) public SocketManager(string name, bool useHighPrioritySocketThreads)
: this(name, useHighPrioritySocketThreads, DEFAULT_MIN_THREADS, DEFAULT_MAX_THREADS) {} : this(name, useHighPrioritySocketThreads, DEFAULT_MIN_THREADS, DEFAULT_MAX_THREADS) { }
private const int DEFAULT_MIN_THREADS = 1, DEFAULT_MAX_THREADS = 5;
const int DEFAULT_MIN_THREADS = 1, DEFAULT_MAX_THREADS = 5;
private SocketManager(string name, bool useHighPrioritySocketThreads, int minThreads, int maxThreads) private SocketManager(string name, bool useHighPrioritySocketThreads, int minThreads, int maxThreads)
{ {
if (string.IsNullOrWhiteSpace(name)) name = GetType().Name; if (string.IsNullOrWhiteSpace(name)) name = GetType().Name;
Name = name; Name = name;
const long Receive_PauseWriterThreshold = 4L * 1024 * 1024 * 1024; // let's give it up to 4GiB of buffer for now const long Receive_PauseWriterThreshold = 4L * 1024 * 1024 * 1024; // let's give it up to 4GiB of buffer for now
const long Receive_ResumeWriterThreshold = 3L * 1024 * 1024 * 1024; const long Receive_ResumeWriterThreshold = 3L * 1024 * 1024 * 1024;
var defaultPipeOptions = PipeOptions.Default; var defaultPipeOptions = PipeOptions.Default;
_scheduler = new DedicatedThreadPoolPipeScheduler(name, _scheduler = new DedicatedThreadPoolPipeScheduler(name,
minWorkers: minThreads, maxWorkers: maxThreads, minWorkers: minThreads, maxWorkers: maxThreads,
priority: useHighPrioritySocketThreads ? ThreadPriority.AboveNormal :ThreadPriority.Normal); priority: useHighPrioritySocketThreads ? ThreadPriority.AboveNormal : ThreadPriority.Normal);
SendPipeOptions = new PipeOptions( SendPipeOptions = new PipeOptions(
defaultPipeOptions.Pool, _scheduler, _scheduler, defaultPipeOptions.Pool, _scheduler, _scheduler,
pauseWriterThreshold: defaultPipeOptions.PauseWriterThreshold, pauseWriterThreshold: defaultPipeOptions.PauseWriterThreshold,
...@@ -170,7 +174,8 @@ private SocketManager(string name, bool useHighPrioritySocketThreads, int minThr ...@@ -170,7 +174,8 @@ private SocketManager(string name, bool useHighPrioritySocketThreads, int minThr
defaultPipeOptions.MinimumSegmentSize, defaultPipeOptions.MinimumSegmentSize,
useSynchronizationContext: false); useSynchronizationContext: false);
} }
DedicatedThreadPoolPipeScheduler _scheduler;
private DedicatedThreadPoolPipeScheduler _scheduler;
internal readonly PipeOptions SendPipeOptions, ReceivePipeOptions; internal readonly PipeOptions SendPipeOptions, ReceivePipeOptions;
private enum CallbackOperation private enum CallbackOperation
...@@ -183,6 +188,7 @@ private enum CallbackOperation ...@@ -183,6 +188,7 @@ private enum CallbackOperation
/// Releases all resources associated with this instance /// Releases all resources associated with this instance
/// </summary> /// </summary>
public void Dispose() => Dispose(true); public void Dispose() => Dispose(true);
private void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
// note: the scheduler *can't* be collected by itself - there will // note: the scheduler *can't* be collected by itself - there will
...@@ -195,12 +201,13 @@ private void Dispose(bool disposing) ...@@ -195,12 +201,13 @@ private void Dispose(bool disposing)
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
OnDispose(); OnDispose();
} }
} }
/// <summary> /// <summary>
/// Releases *appropriate* resources associated with this instance /// Releases *appropriate* resources associated with this instance
/// </summary> /// </summary>
~SocketManager() => Dispose(false); ~SocketManager() => Dispose(false);
internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log) internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log)
{ {
void RunWithCompletionType(Func<AsyncCallback, IAsyncResult> beginAsync, AsyncCallback asyncCallback) void RunWithCompletionType(Func<AsyncCallback, IAsyncResult> beginAsync, AsyncCallback asyncCallback)
...@@ -221,7 +228,6 @@ void proxyCallback(IAsyncResult ar) ...@@ -221,7 +228,6 @@ void proxyCallback(IAsyncResult ar)
} }
} }
var addressFamily = endpoint.AddressFamily == AddressFamily.Unspecified ? AddressFamily.InterNetwork : endpoint.AddressFamily; var addressFamily = endpoint.AddressFamily == AddressFamily.Unspecified ? AddressFamily.InterNetwork : endpoint.AddressFamily;
var protocolType = addressFamily == AddressFamily.Unix ? ProtocolType.Unspecified : ProtocolType.Tcp; var protocolType = addressFamily == AddressFamily.Unix ? ProtocolType.Unspecified : ProtocolType.Tcp;
var socket = new Socket(addressFamily, SocketType.Stream, protocolType); var socket = new Socket(addressFamily, SocketType.Stream, protocolType);
...@@ -237,7 +243,8 @@ void proxyCallback(IAsyncResult ar) ...@@ -237,7 +243,8 @@ void proxyCallback(IAsyncResult ar)
{ {
RunWithCompletionType( RunWithCompletionType(
cb => socket.BeginConnect(dnsEndpoint.Host, dnsEndpoint.Port, cb, tuple), cb => socket.BeginConnect(dnsEndpoint.Host, dnsEndpoint.Port, cb, tuple),
ar => { ar =>
{
multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint); multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint);
EndConnectImpl(ar, multiplexer, log, tuple); EndConnectImpl(ar, multiplexer, log, tuple);
multiplexer.LogLocked(log, "Connect complete: {0}", formattedEndpoint); multiplexer.LogLocked(log, "Connect complete: {0}", formattedEndpoint);
...@@ -247,7 +254,8 @@ void proxyCallback(IAsyncResult ar) ...@@ -247,7 +254,8 @@ void proxyCallback(IAsyncResult ar)
{ {
RunWithCompletionType( RunWithCompletionType(
cb => socket.BeginConnect(endpoint, cb, tuple), cb => socket.BeginConnect(endpoint, cb, tuple),
ar => { ar =>
{
multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint); multiplexer.LogLocked(log, "EndConnect: {0}", formattedEndpoint);
EndConnectImpl(ar, multiplexer, log, tuple); EndConnectImpl(ar, multiplexer, log, tuple);
multiplexer.LogLocked(log, "Connect complete: {0}", formattedEndpoint); multiplexer.LogLocked(log, "Connect complete: {0}", formattedEndpoint);
...@@ -313,7 +321,7 @@ private async void EndConnectImpl(IAsyncResult ar, ConnectionMultiplexer multipl ...@@ -313,7 +321,7 @@ private async void EndConnectImpl(IAsyncResult ar, ConnectionMultiplexer multipl
} }
} }
} }
catch(Exception outer) catch (Exception outer)
{ {
ConnectionMultiplexer.TraceWithoutContext(outer.Message); ConnectionMultiplexer.TraceWithoutContext(outer.Message);
if (callback != null) if (callback != null)
......
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