Procházet zdrojové kódy

修复一个TCP TSocket的抛出异常的bug

tanghai před 9 roky
rodič
revize
c036f80f1f

+ 11 - 1
Unity/Assets/Editor/ServerCommandLineEditor/ServerCommandLineEditor.cs

@@ -44,6 +44,15 @@ namespace MyEditor
 			}
 		}
 
+		public void ClearConfig()
+		{
+			foreach (StartConfig startConfig in this.startConfigs)
+			{
+				startConfig.Dispose();
+			}
+			this.startConfigs.Clear();
+		}
+
 		private List<string> GetConfigFiles()
 		{
 			List<string> fs = Directory.GetFiles(ConfigDir).ToList();
@@ -64,7 +73,7 @@ namespace MyEditor
 			string s2 = "";
 			try
 			{
-				this.startConfigs.Clear();
+				this.ClearConfig();
 				string[] ss = File.ReadAllText(filePath).Split('\n');
 				foreach (string s in ss)
 				{
@@ -293,6 +302,7 @@ namespace MyEditor
 
 		private void OnDestroy()
 		{
+			this.ClearConfig();
 		}
 	}
 }

+ 8 - 0
Unity/Assets/Plugins/Base/Network/TNet/TChannel.cs

@@ -121,6 +121,10 @@ namespace Base
 
 		private void StartSend()
 		{
+			if (this.Id == 0)
+			{
+				return;
+			}
 			// 没有数据需要发送
 			if (this.sendBuffer.Count == 0)
 			{
@@ -168,6 +172,10 @@ namespace Base
 
 		private void StartRecv()
 		{
+			if (this.Id == 0)
+			{
+				return;
+			}
 			int size = TBuffer.ChunkSize - this.recvBuffer.LastIndex;
 			
 			if (!this.socket.RecvAsync(this.recvBuffer.Last, this.recvBuffer.LastIndex, size))

+ 1 - 1
Unity/Assets/Plugins/Base/Network/TNet/TService.cs

@@ -38,7 +38,7 @@ namespace Base
 				TChannel channel = this.idChannels[id];
 				channel.Dispose();
 			}
-			this.acceptor.Dispose();
+			this.acceptor?.Dispose();
 			this.poller = null;
 		}
 

+ 21 - 1
Unity/Assets/Plugins/Base/Network/TNet/TSocket.cs

@@ -97,8 +97,12 @@ namespace Base
 			return tcs.Task;
 		}
 
-		private static void OnAcceptComplete(SocketAsyncEventArgs e)
+		private void OnAcceptComplete(SocketAsyncEventArgs e)
 		{
+			if (this.socket == null)
+			{
+				return;
+			}
 			var tcs = (TaskCompletionSource<bool>)e.UserToken;
 			e.UserToken = null;
 			if (e.SocketError != SocketError.Success)
@@ -150,6 +154,10 @@ namespace Base
 
 		private void OnConnectComplete(SocketAsyncEventArgs e)
 		{
+			if (this.socket == null)
+			{
+				return;
+			}
 			if (this.OnConn == null)
 			{
 				return;
@@ -177,6 +185,10 @@ namespace Base
 
 		private void OnRecvComplete(SocketAsyncEventArgs e)
 		{
+			if (this.socket == null)
+			{
+				return;
+			}
 			if (this.OnRecv == null)
 			{
 				return;
@@ -204,6 +216,10 @@ namespace Base
 
 		private void OnSendComplete(SocketAsyncEventArgs e)
 		{
+			if (this.socket == null)
+			{
+				return;
+			}
 			if (this.OnSend == null)
 			{
 				return;
@@ -213,6 +229,10 @@ namespace Base
 
 		private void OnDisconnectComplete(SocketAsyncEventArgs e)
 		{
+			if (this.socket == null)
+			{
+				return;
+			}
 			if (this.OnDisconnect == null)
 			{
 				return;