Просмотр исходного кода

AChannel的OnError不需要再传个AChannel进去

tanghai 8 лет назад
Родитель
Сommit
cd7dec9142

+ 1 - 1
Client-Server.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 15
-VisualStudioVersion = 15.0.27130.2027
+VisualStudioVersion = 15.0.27130.2036
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Plugins", "Unity\Unity.Plugins.csproj", "{D1FDB199-0FB7-099D-3771-C6A942E4E326}"
 EndProject

+ 6 - 2
Unity/Assets/Scripts/Module/Message/Network/AChannel.cs

@@ -43,9 +43,13 @@ namespace Model
 			}
 		}
 
-		protected void OnError(AChannel channel, SocketError e)
+		protected void OnError(SocketError e)
 		{
-			this.errorCallback?.Invoke(channel, e);
+			if (this.IsDisposed)
+			{
+				return;
+			}
+			this.errorCallback?.Invoke(this, e);
 		}
 
 

+ 2 - 2
Unity/Assets/Scripts/Module/Message/Network/KCP/KChannel.cs

@@ -154,7 +154,7 @@ namespace Model
 			// 超时断开连接
 			if (timeNow - this.lastRecvTime > 20 * 1000)
 			{
-				this.OnError(this, SocketError.Disconnecting);
+				this.OnError(SocketError.Disconnecting);
 				return;
 			}
 			this.kcp.Update(timeNow);
@@ -186,7 +186,7 @@ namespace Model
 				int n = kcp.PeekSize();
 				if (n == 0)
 				{
-					this.OnError(this, SocketError.NetworkReset);
+					this.OnError(SocketError.NetworkReset);
 					return;
 				}
 				int count = this.kcp.Recv(this.cacheBytes);

+ 15 - 5
Unity/Assets/Scripts/Module/Message/Network/TCP/TChannel.cs

@@ -58,11 +58,11 @@ namespace Model
 			catch (SocketException e)
 			{
 				Log.Error($"connect error: {e.SocketErrorCode}");
-				this.OnError(this, e.SocketErrorCode);
+				this.OnError(e.SocketErrorCode);
 			}
 			catch (Exception e)
 			{
-				this.OnError(this, SocketError.SocketError);
+				this.OnError(SocketError.SocketError);
 				Log.Error($"connect error: {ipEndPoint} {e}");
 			}
 		}
@@ -161,13 +161,18 @@ namespace Model
 					await this.sendBuffer.ReadAsync(stream);
 				}
 			}
+			catch (IOException)
+			{
+				this.OnError(SocketError.SocketError);
+			}
 			catch (ObjectDisposedException)
 			{
+				this.OnError(SocketError.SocketError);
 			}
 			catch (Exception e)
 			{
 				Log.Error(e.ToString());
-				this.OnError(this, SocketError.SocketError);
+				this.OnError(SocketError.SocketError);
 			}
 		}
 
@@ -192,7 +197,7 @@ namespace Model
 
 					if (n == 0)
 					{
-						this.OnError(this, SocketError.NetworkReset);
+						this.OnError(SocketError.NetworkReset);
 						return;
 					}
 
@@ -210,13 +215,18 @@ namespace Model
 					}
 				}
 			}
+			catch (IOException)
+			{
+				this.OnError(SocketError.SocketError);
+			}
 			catch (ObjectDisposedException)
 			{
+				this.OnError(SocketError.SocketError);
 			}
 			catch (Exception e)
 			{
 				Log.Error(e.ToString());
-				this.OnError(this, SocketError.SocketError);
+				this.OnError(SocketError.SocketError);
 			}
 		}