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()
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
{
const SocketMode socketMode = SocketMode.Async;
// disallow connection in some cases
OnDebugAbort();
......@@ -901,7 +899,7 @@ internal async ValueTask<SocketMode> ConnectedAsync(Socket socket, TextWriter lo
{
RecordConnectionFailed(ConnectionFailureType.AuthenticationFailure, authexception);
Multiplexer.Trace("Encryption failure");
return SocketMode.Abort;
return false;
}
pipe = StreamConnection.GetDuplex(ssl, manager.SendPipeOptions, manager.ReceivePipeOptions, name: Bridge.Name);
}
......@@ -915,14 +913,14 @@ internal async ValueTask<SocketMode> ConnectedAsync(Socket socket, TextWriter lo
Multiplexer.LogLocked(log, "Connected {0}", Bridge);
await Bridge.OnConnectedAsync(this, log);
return socketMode;
await Bridge.OnConnectedAsync(this, log).ForAwait();
return true;
}
catch (Exception ex)
{
RecordConnectionFailed(ConnectionFailureType.InternalFailure, ex); // includes a bridge.OnDisconnected
Multiplexer.Trace("Could not connect: " + ex.Message, physicalName);
return SocketMode.Abort;
return false;
}
}
......
......@@ -9,12 +9,6 @@
namespace StackExchange.Redis
{
internal enum SocketMode
{
Abort,
Async,
}
/// <summary>
/// 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
......@@ -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)
{
var formattedEndpoint = Format.ToString(endpoint);
multiplexer.LogLocked(log, "BeginConnect: {0}", formattedEndpoint);
multiplexer.LogLocked(log, "BeginConnect: {0}", Format.ToString(endpoint));
var awaitable = new SocketAwaitable();
var args = new SocketAsyncEventArgs
......@@ -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)
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");
try
{
physicalConnection.StartReading();
}
catch (Exception ex)
{
ConnectionMultiplexer.TraceWithoutContext(ex.Message);
Shutdown(socket);
}
break;
default:
ConnectionMultiplexer.TraceWithoutContext("Aborting socket");
multiplexer.LogLocked(log, "Starting read");
try
{
physicalConnection.StartReading();
// Normal return
}
catch (Exception ex)
{
ConnectionMultiplexer.TraceWithoutContext(ex.Message);
Shutdown(socket);
break;
}
}
else
{
ConnectionMultiplexer.TraceWithoutContext("Aborting socket");
Shutdown(socket);
}
}
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