Cache remote endpoint to prevent ObjectDisposedException
This commit is contained in:
parent
ca55005c30
commit
b8df2c50c4
|
@ -17,6 +17,7 @@ public abstract class BaseClientNode : Node
|
||||||
{
|
{
|
||||||
private readonly ObjectIDGenerator _callbackIdGenerator = new();
|
private readonly ObjectIDGenerator _callbackIdGenerator = new();
|
||||||
private readonly ConcurrentDictionary<int, List<TaskCompletionSource<Packet>>> _packetCompletionSources = new();
|
private readonly ConcurrentDictionary<int, List<TaskCompletionSource<Packet>>> _packetCompletionSources = new();
|
||||||
|
private EndPoint? _remoteEP;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="BaseClientNode" /> class.
|
/// Initializes a new instance of the <see cref="BaseClientNode" /> class.
|
||||||
|
@ -36,8 +37,11 @@ public abstract class BaseClientNode : Node
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The <see cref="EndPoint" /> with which the client is communicating.</value>
|
/// <value>The <see cref="EndPoint" /> with which the client is communicating.</value>
|
||||||
/// <exception cref="SocketException">An error occurred when attempting to access the socket.</exception>
|
/// <exception cref="SocketException">An error occurred when attempting to access the socket.</exception>
|
||||||
/// <exception cref="ObjectDisposedException"><see cref="Node.BaseSocket" /> has been closed.</exception>
|
public EndPoint RemoteEndPoint
|
||||||
public EndPoint RemoteEndPoint => BaseSocket.RemoteEndPoint;
|
{
|
||||||
|
get => _remoteEP ??= BaseSocket.RemoteEndPoint;
|
||||||
|
internal set => _remoteEP = value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the session ID of the client.
|
/// Gets the session ID of the client.
|
||||||
|
|
|
@ -91,6 +91,7 @@ public sealed class ProtocolClient : BaseClientNode
|
||||||
}
|
}
|
||||||
|
|
||||||
IsConnected = true;
|
IsConnected = true;
|
||||||
|
RemoteEndPoint = BaseSocket.RemoteEndPoint;
|
||||||
|
|
||||||
State = ClientState.Handshaking;
|
State = ClientState.Handshaking;
|
||||||
var handshakeRequest = new HandshakeRequestPacket(ProtocolVersion);
|
var handshakeRequest = new HandshakeRequestPacket(ProtocolVersion);
|
||||||
|
|
|
@ -16,6 +16,7 @@ public sealed partial class ProtocolListener
|
||||||
BaseSocket = socket ?? throw new ArgumentNullException(nameof(socket));
|
BaseSocket = socket ?? throw new ArgumentNullException(nameof(socket));
|
||||||
SessionId = Guid.NewGuid();
|
SessionId = Guid.NewGuid();
|
||||||
IsConnected = true;
|
IsConnected = true;
|
||||||
|
RemoteEndPoint = socket.RemoteEndPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue