Parcourir la source

修复一个TCP小bug,channel start应该放到Session加入集合之后执行,否则recv可能解析失败删除session发现删除不了

tanghai il y a 7 ans
Parent
commit
e11f096d16

+ 9 - 3
Unity/Assets/Scripts/Module/Message/Network/TCP/TChannel.cs

@@ -24,6 +24,8 @@ namespace ETModel
 
 		private bool isSending;
 
+		private bool isRecving;
+
 		private bool isConnected;
 
 		private readonly PacketParser parser;
@@ -102,9 +104,13 @@ namespace ETModel
 				this.ConnectAsync(this.RemoteAddress);
 				return;
 			}
-			
-			this.StartRecv();
-			
+
+			if (!this.isRecving)
+			{
+				this.isRecving = true;
+				this.StartRecv();
+			}
+
 			this.GetService().MarkNeedStartSend(this.Id);
 		}
 		

+ 3 - 0
Unity/Assets/Scripts/Module/Message/NetworkComponent.cs

@@ -76,6 +76,7 @@ namespace ETModel
 		{
 			Session session = ComponentFactory.CreateWithParent<Session, AChannel>(this, channel);
 			this.sessions.Add(session.Id, session);
+			session.Start();
 		}
 
 		public virtual void Remove(long id)
@@ -104,6 +105,7 @@ namespace ETModel
 			AChannel channel = this.Service.ConnectChannel(ipEndPoint);
 			Session session = ComponentFactory.CreateWithParent<Session, AChannel>(this, channel);
 			this.sessions.Add(session.Id, session);
+			session.Start();
 			return session;
 		}
 		
@@ -115,6 +117,7 @@ namespace ETModel
 			AChannel channel = this.Service.ConnectChannel(address);
 			Session session = ComponentFactory.CreateWithParent<Session, AChannel>(this, channel);
 			this.sessions.Add(session.Id, session);
+			session.Start();
 			return session;
 		}
 

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

@@ -56,9 +56,8 @@ namespace ETModel
 				this.Network.Remove(id); 
 			};
 			channel.ReadCallback += this.OnRead;
-			
-			this.channel.Start();
 		}
+		
 		public override void Dispose()
 		{
 			if (this.IsDisposed)
@@ -86,6 +85,11 @@ namespace ETModel
 			this.requestCallback.Clear();
 		}
 
+		public void Start()
+		{
+			this.channel.Start();
+		}
+
 		public IPEndPoint RemoteAddress
 		{
 			get