From 6e30275d2db84db8a1e35b22a74c0c95ffd5e3ac Mon Sep 17 00:00:00 2001 From: SALTWOOD <105980161+SALTWOOD@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:52:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20RsaStream=20=E9=87=8D=E5=86=99=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E7=9A=84=20Dispose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Network/RsaStream.cs | 15 ++++++++++++++- Network/RsaStreamStatus.cs | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Network/RsaStream.cs b/Network/RsaStream.cs index 0591632..ace7a45 100644 --- a/Network/RsaStream.cs +++ b/Network/RsaStream.cs @@ -13,7 +13,7 @@ namespace TeraIO.Network; -public class RsaStream : Stream +public class RsaStream : Stream, IDisposable { protected readonly Stream _stream; protected RSA _rsaPrivate; @@ -225,4 +225,17 @@ public override void Close() } #endregion + + #region IDisposable Overrides + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (disposing) + { + this.Close(); + _stream.Dispose(); + this.Status = RsaStreamStatus.Disposed; + } + } + #endregion } \ No newline at end of file diff --git a/Network/RsaStreamStatus.cs b/Network/RsaStreamStatus.cs index 036de24..7038c2b 100644 --- a/Network/RsaStreamStatus.cs +++ b/Network/RsaStreamStatus.cs @@ -12,6 +12,7 @@ public enum RsaStreamStatus Handshaking, Established, Closed, + Disposed, Failed = 100, AuthenticationFailed = 101, ProtocolVersionMismatch = 102