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

1.修复了udp无法连接发消息的bug
2.去掉了Service中的Add接口,可以用同步上下文替代

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

+ 0 - 6
Unity/Assets/Scripts/Base/Network/AService.cs

@@ -11,12 +11,6 @@ namespace Model
 
 	public abstract class AService: IDisposable
 	{
-		/// <summary>
-		/// 将函数调用加入IService线程
-		/// </summary>
-		/// <param name="action"></param>
-		public abstract void Add(Action action);
-
 		public abstract AChannel GetChannel(long id);
 
 		public abstract Task<AChannel> AcceptChannel();

+ 0 - 4
Unity/Assets/Scripts/Base/Network/TNet/TService.cs

@@ -44,10 +44,6 @@ namespace Model
 			this.acceptor = null;
 		}
 
-		public override void Add(Action action)
-		{
-		}
-
 		public override AChannel GetChannel(long id)
 		{
 			TChannel channel = null;

+ 1 - 32
Unity/Assets/Scripts/Base/Network/UNet/UPoller.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Collections.Generic;
 using System.Threading.Tasks;
 
 namespace Model
@@ -15,12 +14,7 @@ namespace Model
 		private readonly EQueue<IntPtr> connQueue = new EQueue<IntPtr>();
 
 		private IntPtr host;
-
-		// 线程同步队列,发送接收socket回调都放到该队列,由poll线程统一执行
-		private EQueue<Action> concurrentQueue = new EQueue<Action>();
-		private EQueue<Action> localQueue;
-		private readonly object lockObject = new object();
-
+		
 		private ENetEvent eNetEventCache;
 
 		private TaskCompletionSource<USocket> AcceptTcs { get; set; }
@@ -88,14 +82,6 @@ namespace Model
 			NativeMethods.enet_host_flush(this.host);
 		}
 
-		public void Add(Action action)
-		{
-			lock (lockObject)
-			{
-				this.concurrentQueue.Enqueue(action);
-			}
-		}
-
 		public Task<USocket> AcceptAsync()
 		{
 			if (this.AcceptTcs != null)
@@ -133,21 +119,6 @@ namespace Model
 			tcs.SetResult(socket);
 		}
 
-		private void OnEvents()
-		{
-			lock (lockObject)
-			{
-				localQueue = concurrentQueue;
-				concurrentQueue = new EQueue<Action>();
-			}
-
-			while (this.localQueue.Count > 0)
-			{
-				Action a = this.localQueue.Dequeue();
-				a();
-			}
-		}
-
 		private int Service()
 		{
 			int ret = NativeMethods.enet_host_service(this.host, IntPtr.Zero, 0);
@@ -156,8 +127,6 @@ namespace Model
 
 		public void Update()
 		{
-			this.OnEvents();
-
 			if (this.Service() < 0)
 			{
 				return;

+ 1 - 7
Unity/Assets/Scripts/Base/Network/UNet/UService.cs

@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 
@@ -42,11 +41,6 @@ namespace Model
 			
 			this.poller = null;
 		}
-
-		public override void Add(Action action)
-		{
-			this.poller.Add(action);
-		}
 		
 		public override async Task<AChannel> AcceptChannel()
 		{

+ 6 - 1
Unity/Assets/Scripts/Component/NetOuterComponent.cs

@@ -1,7 +1,7 @@
 namespace Model
 {
 	[ObjectEvent]
-	public class NetOuterComponentEvent : ObjectEvent<NetOuterComponent>, IAwake, IAwake<string, int>
+	public class NetOuterComponentEvent : ObjectEvent<NetOuterComponent>, IAwake, IAwake<string, int>, IUpdate
 	{
 		public void Awake()
 		{
@@ -12,6 +12,11 @@
 		{
 			this.Get().Awake();
 		}
+
+		public void Update()
+		{
+			this.Get().Update();
+		}
 	}
 
 	public class NetOuterComponent : NetworkComponent