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

修复一个kcp分片的bug,et7改到et8改出来的问题

tanghai 2 лет назад
Родитель
Сommit
1d03fd8c01

+ 5 - 5
Unity/Assets/Scripts/Core/Network/AService.cs

@@ -14,21 +14,21 @@ namespace ET
         public long Id { get; set; }
         
         public ServiceType ServiceType { get; protected set; }
-        
-        public const int MaxCacheBufferSize = 1024;
+
+        private const int MaxMemoryBufferSize = 1024;
 		
         private readonly Queue<MemoryBuffer> pool = new();
 
         public MemoryBuffer Fetch(int size = 0)
         {
-            if (size > MaxCacheBufferSize)
+            if (size > MaxMemoryBufferSize)
             {
                 return new MemoryBuffer(size);
             }
             
-            if (size < MaxCacheBufferSize)
+            if (size < MaxMemoryBufferSize)
             {
-                size = MaxCacheBufferSize;
+                size = MaxMemoryBufferSize;
             }
             
             if (this.pool.Count == 0)

+ 7 - 4
Unity/Assets/Scripts/Core/Network/KChannel.cs

@@ -9,6 +9,8 @@ namespace ET
 {
 	public class KChannel : AChannel
 	{
+		private const int MaxKcpMessageSize = 10000;
+		
 		private readonly KService Service;
 
 		private Kcp kcp { get; set; }
@@ -319,7 +321,7 @@ namespace ET
 						if (headInt == 0)
 						{
 							this.needReadSplitCount = BitConverter.ToInt32(readMemory.GetBuffer(), 4);
-							if (this.needReadSplitCount <= AService.MaxCacheBufferSize)
+							if (this.needReadSplitCount <= MaxKcpMessageSize)
 							{
 								Log.Error($"kchannel read error3: {this.needReadSplitCount} {this.LocalConn} {this.RemoteConn}");
 								this.OnError(ErrorCore.ERR_KcpSplitCountError);
@@ -349,7 +351,7 @@ namespace ET
 			}
 		}
 
-		public void Output(byte[] bytes, int count)
+		private void Output(byte[] bytes, int count)
 		{
 			if (this.IsDisposed)
 			{
@@ -405,7 +407,8 @@ namespace ET
 			int count = (int) (memoryStream.Length - memoryStream.Position);
 
 			// 超出maxPacketSize需要分片
-			if (count <= AService.MaxCacheBufferSize)
+			
+			if (count <= MaxKcpMessageSize)
 			{
 				this.kcp.Send(memoryStream.GetBuffer().AsSpan((int)memoryStream.Position, count));
 			}
@@ -422,7 +425,7 @@ namespace ET
 				{
 					int leftCount = count - alreadySendCount;
 					
-					int sendCount = leftCount < AService.MaxCacheBufferSize? leftCount: AService.MaxCacheBufferSize;
+					int sendCount = leftCount < MaxKcpMessageSize? leftCount: MaxKcpMessageSize;
 					
 					this.kcp.Send(memoryStream.GetBuffer().AsSpan((int)memoryStream.Position + alreadySendCount, sendCount));