Commit d27870d4 authored by Nick Craver's avatar Nick Craver Committed by Nick Craver

Remove SocketMode

This is pretty much a boolean now...let's make it one. Also note PhysicalConnection is passes as `this`, it can't be null.
parent 85a4cc71
...@@ -860,12 +860,10 @@ private static LocalCertificateSelectionCallback GetAmbientCertificateCallback() ...@@ -860,12 +860,10 @@ private static LocalCertificateSelectionCallback GetAmbientCertificateCallback()
return null; return null;
} }
internal async ValueTask<SocketMode> ConnectedAsync(Socket socket, TextWriter log, SocketManager manager) internal async ValueTask<bool> ConnectedAsync(Socket socket, TextWriter log, SocketManager manager)
{ {
try try
{ {
const SocketMode socketMode = SocketMode.Async;
// disallow connection in some cases // disallow connection in some cases
OnDebugAbort(); OnDebugAbort();
...@@ -901,7 +899,7 @@ internal async ValueTask<SocketMode> ConnectedAsync(Socket socket, TextWriter lo ...@@ -901,7 +899,7 @@ internal async ValueTask<SocketMode> ConnectedAsync(Socket socket, TextWriter lo
{ {
RecordConnectionFailed(ConnectionFailureType.AuthenticationFailure, authexception); RecordConnectionFailed(ConnectionFailureType.AuthenticationFailure, authexception);
Multiplexer.Trace("Encryption failure"); Multiplexer.Trace("Encryption failure");
return SocketMode.Abort; return false;
} }
pipe = StreamConnection.GetDuplex(ssl, manager.SendPipeOptions, manager.ReceivePipeOptions, name: Bridge.Name); pipe = StreamConnection.GetDuplex(ssl, manager.SendPipeOptions, manager.ReceivePipeOptions, name: Bridge.Name);
} }
...@@ -915,14 +913,14 @@ internal async ValueTask<SocketMode> ConnectedAsync(Socket socket, TextWriter lo ...@@ -915,14 +913,14 @@ internal async ValueTask<SocketMode> ConnectedAsync(Socket socket, TextWriter lo
Multiplexer.LogLocked(log, "Connected {0}", Bridge); Multiplexer.LogLocked(log, "Connected {0}", Bridge);
await Bridge.OnConnectedAsync(this, log); await Bridge.OnConnectedAsync(this, log).ForAwait();
return socketMode; return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
RecordConnectionFailed(ConnectionFailureType.InternalFailure, ex); // includes a bridge.OnDisconnected RecordConnectionFailed(ConnectionFailureType.InternalFailure, ex); // includes a bridge.OnDisconnected
Multiplexer.Trace("Could not connect: " + ex.Message, physicalName); Multiplexer.Trace("Could not connect: " + ex.Message, physicalName);
return SocketMode.Abort; return false;
} }
} }
......
...@@ -9,12 +9,6 @@ ...@@ -9,12 +9,6 @@
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
internal enum SocketMode
{
Abort,
Async,
}
/// <summary> /// <summary>
/// A SocketManager monitors multiple sockets for availability of data; this is done using /// A SocketManager monitors multiple sockets for availability of data; this is done using
/// the Socket.Select API and a dedicated reader-thread, which allows for fast responses /// the Socket.Select API and a dedicated reader-thread, which allows for fast responses
...@@ -150,8 +144,7 @@ private static void ConfigureTimeout(SocketAsyncEventArgs args, int timeoutMilli ...@@ -150,8 +144,7 @@ private static void ConfigureTimeout(SocketAsyncEventArgs args, int timeoutMilli
internal async void BeginConnectAsync(EndPoint endpoint, Socket socket, PhysicalConnection physicalConnection, ConnectionMultiplexer multiplexer, TextWriter log) internal async void BeginConnectAsync(EndPoint endpoint, Socket socket, PhysicalConnection physicalConnection, ConnectionMultiplexer multiplexer, TextWriter log)
{ {
var formattedEndpoint = Format.ToString(endpoint); multiplexer.LogLocked(log, "BeginConnect: {0}", Format.ToString(endpoint));
multiplexer.LogLocked(log, "BeginConnect: {0}", formattedEndpoint);
var awaitable = new SocketAwaitable(); var awaitable = new SocketAwaitable();
var args = new SocketAsyncEventArgs var args = new SocketAsyncEventArgs
...@@ -180,24 +173,24 @@ internal async void BeginConnectAsync(EndPoint endpoint, Socket socket, Physical ...@@ -180,24 +173,24 @@ internal async void BeginConnectAsync(EndPoint endpoint, Socket socket, Physical
await awaitable; // wait for the connect to complete or fail (will throw) await awaitable; // wait for the connect to complete or fail (will throw)
switch (physicalConnection == null ? SocketMode.Abort : await physicalConnection.ConnectedAsync(socket, log, this).ForAwait()) if (physicalConnection != null && await physicalConnection.ConnectedAsync(socket, log, this).ForAwait())
{ {
case SocketMode.Async:
multiplexer.LogLocked(log, "Starting read"); multiplexer.LogLocked(log, "Starting read");
try try
{ {
physicalConnection.StartReading(); physicalConnection.StartReading();
// Normal return
} }
catch (Exception ex) catch (Exception ex)
{ {
ConnectionMultiplexer.TraceWithoutContext(ex.Message); ConnectionMultiplexer.TraceWithoutContext(ex.Message);
Shutdown(socket); Shutdown(socket);
} }
break; }
default: else
{
ConnectionMultiplexer.TraceWithoutContext("Aborting socket"); ConnectionMultiplexer.TraceWithoutContext("Aborting socket");
Shutdown(socket); Shutdown(socket);
break;
} }
} }
catch (ObjectDisposedException) catch (ObjectDisposedException)
......
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