Commit 2629e253 authored by Marc Gravell's avatar Marc Gravell

remove SocketToken - that abstraction is no longer useful with the unified Socket code

parent d8e8eb0c
......@@ -72,7 +72,7 @@ private static readonly Message
private IDuplexPipe _ioPipe;
private SocketToken socketToken;
private Socket _socket;
public PhysicalConnection(PhysicalBridge bridge)
{
......@@ -94,7 +94,7 @@ public void BeginConnect(TextWriter log)
var endpoint = Bridge.ServerEndPoint.EndPoint;
Multiplexer.Trace("Connecting...", physicalName);
socketToken = Multiplexer.SocketManager.BeginConnect(endpoint, this, Multiplexer, log);
_socket = Multiplexer.SocketManager.BeginConnect(endpoint, this, Multiplexer, log);
}
private enum ReadMode : byte
......@@ -129,10 +129,10 @@ public void Dispose()
}
try { using (ioPipe as IDisposable) { } } catch { }
if (socketToken.HasValue)
if (_socket != null)
{
Multiplexer.SocketManager?.Shutdown(socketToken);
socketToken = default(SocketToken);
Multiplexer.SocketManager?.Shutdown(_socket);
_socket = default;
Multiplexer.Trace("Disconnected", physicalName);
RecordConnectionFailed(ConnectionFailureType.ConnectionDisposed);
}
......@@ -255,7 +255,7 @@ void add(string lk, string sk, string v)
// burn the socket
managerState = SocketManager.ManagerState.RecordConnectionFailed_ShutdownSocket;
Multiplexer.SocketManager?.Shutdown(socketToken);
Multiplexer.SocketManager?.Shutdown(_socket);
}
public override string ToString()
......@@ -845,7 +845,7 @@ private static void WriteUnified(PipeWriter writer, long value)
writer.Advance(bytes);
}
internal int GetAvailableInboundBytes() => socketToken.Available;
internal int GetAvailableInboundBytes() => _socket?.Available ?? 0;
private static LocalCertificateSelectionCallback GetAmbientCertificateCallback()
{
......@@ -1129,15 +1129,6 @@ private int ProcessBuffer(ref ReadOnlySequence<byte> buffer)
// }
//}
bool ISocketCallback.IsDataAvailable
{
get
{
try { return socketToken.Available > 0; }
catch { return false; }
}
}
private RawResult ReadArray(in ReadOnlySequence<byte> buffer, ref BufferReader reader)
{
var itemCount = ReadLineTerminatedString(ResultType.Integer, in buffer, ref reader);
......
......@@ -47,22 +47,6 @@ internal partial interface ISocketCallback
// check for write-read timeout
void CheckForStaleConnection(ref SocketManager.ManagerState state);
bool IsDataAvailable { get; }
}
internal readonly struct SocketToken
{
internal readonly Socket Socket;
public SocketToken(Socket socket)
{
Socket = socket;
}
public int Available => Socket?.Available ?? 0;
public bool HasValue => Socket != null;
}
/// <summary>
......@@ -213,7 +197,7 @@ private void Dispose(bool disposing)
/// </summary>
~SocketManager() => Dispose(false);
internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log)
internal Socket BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log)
{
void RunWithCompletionType(Func<AsyncCallback, IAsyncResult> beginAsync, AsyncCallback asyncCallback)
{
......@@ -275,15 +259,8 @@ void proxyCallback(IAsyncResult ar)
}
throw;
}
var token = new SocketToken(socket);
return token;
}
internal void Shutdown(SocketToken token)
{
Shutdown(token.Socket);
return socket;
}
private async void EndConnectImpl(IAsyncResult ar, ConnectionMultiplexer multiplexer, TextWriter log, Tuple<Socket, ISocketCallback> tuple)
{
var socket = tuple.Item1;
......@@ -346,7 +323,7 @@ private async void EndConnectImpl(IAsyncResult ar, ConnectionMultiplexer multipl
partial void ShouldIgnoreConnect(ISocketCallback callback, ref bool ignore);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
private void Shutdown(Socket socket)
internal void Shutdown(Socket socket)
{
if (socket != 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