Răsfoiți Sursa

初步实现异步网络库,由于C#Socket是利用线程池发送和接收的,所以必须让发送接收线程完成后回调到poll线程,以后所有游戏逻辑都在poll线程执行

tanghai 11 ani în urmă
părinte
comite
9c6944986e

+ 1 - 1
CSharp/App/Editor/app.config

@@ -36,7 +36,7 @@
 		<add key="Port" value="8888" />
 		<add key="Account" value="egametang@163.com" />
 		<add key="Password" value="163bio1" />
-		<add key="NodePath" value="E:\Source\Demo\battledemo\Assets\Resources\Config\node.bytes" />
+		<add key="NodePath" value="D:\Source\Demo\battledemo\Assets\Resources\Config\node.bytes" />
 	</appSettings>
 
 

+ 4 - 0
CSharp/App/Modules/BehaviorTreeModule/NodeType.cs

@@ -30,6 +30,8 @@
 		HaveSpellWithPrefix = 100017,
 		// 匹配前缀的技能是否在cd中
 		SpellPrefixInCD = 100018,
+		// 开启了跟随模式
+		EnableFollow = 100019,
 
 
 
@@ -46,5 +48,7 @@
 		LeaveTarget = 20009,
 		PathPatrol = 20010,
 		CastPrefixSpell = 20011,
+		// 跟随unit
+		FollowUnit = 20012,
 	}
 }

+ 4 - 4
CSharp/Game/Controller/Controller.csproj

@@ -33,13 +33,13 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="MongoDB.Bson, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+    <Reference Include="MongoDB.Bson, Version=1.10.0.277, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Bson.dll</HintPath>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc0\lib\net35\MongoDB.Bson.dll</HintPath>
     </Reference>
-    <Reference Include="MongoDB.Driver, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+    <Reference Include="MongoDB.Driver, Version=1.10.0.277, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Driver.dll</HintPath>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc0\lib\net35\MongoDB.Driver.dll</HintPath>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />

+ 1 - 1
CSharp/Game/Controller/packages.config

@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="mongocsharpdriver" version="1.9.2" targetFramework="net451" />
+  <package id="mongocsharpdriver" version="1.10.0-rc0" targetFramework="net451" />
 </packages>

+ 4 - 4
CSharp/Game/Model/Model.csproj

@@ -33,13 +33,13 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="MongoDB.Bson, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+    <Reference Include="MongoDB.Bson, Version=1.10.0.277, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Bson.dll</HintPath>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc0\lib\net35\MongoDB.Bson.dll</HintPath>
     </Reference>
-    <Reference Include="MongoDB.Driver, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+    <Reference Include="MongoDB.Driver, Version=1.10.0.277, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Driver.dll</HintPath>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc0\lib\net35\MongoDB.Driver.dll</HintPath>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />

+ 1 - 1
CSharp/Game/Model/packages.config

@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="mongocsharpdriver" version="1.9.2" targetFramework="net451" />
+  <package id="mongocsharpdriver" version="1.10.0-rc0" targetFramework="net451" />
 </packages>

+ 9 - 7
CSharp/Game/MongoDBTest/MongoDBTest.csproj

@@ -38,11 +38,13 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="MongoDB.Bson">
-      <HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Bson.dll</HintPath>
+    <Reference Include="MongoDB.Bson, Version=1.10.0.277, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc0\lib\net35\MongoDB.Bson.dll</HintPath>
     </Reference>
-    <Reference Include="MongoDB.Driver">
-      <HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Driver.dll</HintPath>
+    <Reference Include="MongoDB.Driver, Version=1.10.0.277, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc0\lib\net35\MongoDB.Driver.dll</HintPath>
     </Reference>
     <Reference Include="System" />
   </ItemGroup>
@@ -61,9 +63,6 @@
   <ItemGroup>
     <Compile Include="MongoDBTest.cs" />
   </ItemGroup>
-  <ItemGroup>
-    <None Include="packages.config" />
-  </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\Platform\Common\Common.csproj">
       <Project>{19F8F043-1F99-4550-99DF-DEA5C7D77E55}</Project>
@@ -77,6 +76,9 @@
   <ItemGroup>
     <Folder Include="Properties\" />
   </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
   <Choose>
     <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
       <ItemGroup>

+ 1 - 1
CSharp/Game/MongoDBTest/packages.config

@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="mongocsharpdriver" version="1.9.2" targetFramework="net45" />
+  <package id="mongocsharpdriver" version="1.10.0-rc0" targetFramework="net451" />
 </packages>

+ 4 - 4
CSharp/Platform/Common/Common.csproj

@@ -32,13 +32,13 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="MongoDB.Bson, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+    <Reference Include="MongoDB.Bson, Version=1.10.0.277, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Bson.dll</HintPath>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc0\lib\net35\MongoDB.Bson.dll</HintPath>
     </Reference>
-    <Reference Include="MongoDB.Driver, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+    <Reference Include="MongoDB.Driver, Version=1.10.0.277, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Driver.dll</HintPath>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc0\lib\net35\MongoDB.Driver.dll</HintPath>
     </Reference>
     <Reference Include="NLog, Version=3.1.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>

+ 1 - 1
CSharp/Platform/Common/packages.config

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="mongocsharpdriver" version="1.9.2" targetFramework="net45" />
+  <package id="mongocsharpdriver" version="1.10.0-rc0" targetFramework="net45" />
   <package id="NLog" version="3.1.0.0" targetFramework="net45" />
   <package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
 </packages>

+ 54 - 29
CSharp/Platform/TNet/TBuffer.cs

@@ -5,76 +5,101 @@ namespace TNet
 {
 	public class TBuffer
 	{
-		public const int chunkSize = 8096;
+		public const int ChunkSize = 8096;
 
-		private LinkedList<byte[]> buffer = new LinkedList<byte[]>();
+		private readonly LinkedList<byte[]> bufferList = new LinkedList<byte[]>();
 
-		private int writeIndex;
+		public int LastIndex { get; set; }
 
-		private int readIndex;
+		public int FirstIndex { get; set; }
 
 		public int Count
 		{
 			get
 			{
-				if (this.buffer.Count == 0)
+				if (this.bufferList.Count == 0)
 				{
 					return 0;
 				}
-				return (this.buffer.Count - 1) * chunkSize + this.writeIndex - this.readIndex;
+				return (this.bufferList.Count - 1) * ChunkSize + this.LastIndex - this.FirstIndex;
 			}
 		}
 
-		public byte[] ReadFrom(int n)
+		public void AddLast()
 		{
+			this.bufferList.AddLast(new byte[ChunkSize]);
+		}
+
+		public void RemoveFirst()
+		{
+			this.bufferList.RemoveFirst();
+		}
+
+		public byte[] First
+		{
+			get
+			{
+				return this.bufferList.First.Value;
+			}
+		}
+
+		public byte[] Last
+		{
+			get
+			{
+				return this.bufferList.Last.Value;
+			}
+		}
+
+		public void RecvFrom(byte[] buffer)
+		{
+			int n = buffer.Length;
 			if (this.Count < n || n <= 0)
 			{
-				throw new Exception(string.Format("buffer size < n, buffer: {0} n: {1}", this.Count, n));
+				throw new Exception(string.Format("bufferList size < n, bufferList: {0} n: {1}", this.Count, n));
 			}
-			byte[] bytes = new byte[n];
 			int alreadyCopyCount = n;
 			while (alreadyCopyCount < n)
 			{
-				if (chunkSize - this.readIndex > n - alreadyCopyCount)
+				if (ChunkSize - this.FirstIndex > n - alreadyCopyCount)
 				{
-					Array.Copy(this.buffer.First.Value, this.readIndex, bytes, alreadyCopyCount,
+					Array.Copy(this.bufferList.First.Value, this.FirstIndex, buffer, alreadyCopyCount,
 							n - alreadyCopyCount);
-					this.readIndex += n - alreadyCopyCount;
+					this.FirstIndex += n - alreadyCopyCount;
 					alreadyCopyCount = n;
 				}
 				else
 				{
-					Array.Copy(this.buffer.First.Value, this.readIndex, bytes, alreadyCopyCount,
-							chunkSize - this.readIndex);
-					alreadyCopyCount += chunkSize - this.readIndex;
-					this.readIndex = 0;
-					this.buffer.RemoveFirst();
+					Array.Copy(this.bufferList.First.Value, this.FirstIndex, buffer, alreadyCopyCount,
+							ChunkSize - this.FirstIndex);
+					alreadyCopyCount += ChunkSize - this.FirstIndex;
+					this.FirstIndex = 0;
+					this.bufferList.RemoveFirst();
 				}
 			}
-			return bytes;
 		}
 
-		public void WriteTo(byte[] bytes)
+		public void SendTo(byte[] buffer)
 		{
 			int alreadyCopyCount = 0;
-			while (alreadyCopyCount < bytes.Length)
+			while (alreadyCopyCount < buffer.Length)
 			{
-				if (this.writeIndex == 0)
+				if (this.LastIndex == 0)
 				{
-					this.buffer.AddLast(new byte[chunkSize]);
+					this.bufferList.AddLast(new byte[ChunkSize]);
 				}
-				if (chunkSize - this.writeIndex > alreadyCopyCount)
+				if (ChunkSize - this.LastIndex > alreadyCopyCount)
 				{
-					Array.Copy(bytes, alreadyCopyCount, this.buffer.Last.Value, this.writeIndex, alreadyCopyCount);
-					this.writeIndex += alreadyCopyCount;
+					Array.Copy(buffer, alreadyCopyCount, this.bufferList.Last.Value, this.LastIndex, alreadyCopyCount);
+					this.LastIndex += alreadyCopyCount;
 					alreadyCopyCount = 0;
 				}
 				else
 				{
-					Array.Copy(bytes, alreadyCopyCount, this.buffer.Last.Value, this.writeIndex,
-							chunkSize - this.writeIndex);
-					alreadyCopyCount -= chunkSize - this.writeIndex;
-					this.writeIndex = 0;
+					Array.Copy(buffer, alreadyCopyCount, this.bufferList.Last.Value, this.LastIndex,
+							ChunkSize - this.LastIndex);
+					alreadyCopyCount -= ChunkSize - this.LastIndex;
+					this.LastIndex = 0;
 				}
 			}
 		}

+ 11 - 1
CSharp/Platform/TNet/TNet.csproj

@@ -12,6 +12,8 @@
     <TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <TargetFrameworkProfile />
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <RestorePackages>true</RestorePackages>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -40,11 +42,19 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="TPoller.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="TBuffer.cs" />
-    <Compile Include="TcpAcceptor.cs" />
+    <Compile Include="TSocket.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
+  </Target>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">

+ 66 - 0
CSharp/Platform/TNet/TPoller.cs

@@ -0,0 +1,66 @@
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+
+namespace TNet
+{
+	public class TPoller
+	{
+		private readonly BlockingCollection<TSocketState> blockingCollection = new BlockingCollection<TSocketState>();
+
+		public HashSet<TSocket> CanWriteSocket = new HashSet<TSocket>();
+
+		public void Add(TSocketState tSocketState)
+		{
+			this.blockingCollection.Add(tSocketState);
+		}
+
+		public void Dispose()
+		{
+		}
+
+		public void RunOnce(int timeout)
+		{
+			foreach (TSocket socket in CanWriteSocket)
+			{
+				if (socket.IsSending)
+				{
+					continue;
+				}
+				socket.BeginSend();
+			}
+			this.CanWriteSocket.Clear();
+
+			TSocketState socketState;
+			if (!this.blockingCollection.TryTake(out socketState, timeout))
+			{
+				return;
+			}
+
+			var stateQueue = new Queue<TSocketState>();
+			stateQueue.Enqueue(socketState);
+
+			while (true)
+			{
+				if (!this.blockingCollection.TryTake(out socketState, 0))
+				{
+					break;
+				}
+				stateQueue.Enqueue(socketState);
+			}
+
+			while (stateQueue.Count > 0)
+			{
+				TSocketState state = stateQueue.Dequeue();
+				state.Run();
+			}
+		}
+
+		public void Run()
+		{
+			while (true)
+			{
+				this.RunOnce(1);
+			}
+		}
+	}
+}

+ 166 - 0
CSharp/Platform/TNet/TSocket.cs

@@ -0,0 +1,166 @@
+using System;
+using System.Net.Sockets;
+
+namespace TNet
+{
+	public class TSocketState
+	{
+		public Action Action { get; set; }
+
+		public void Run()
+		{
+			this.Action();
+		}
+	}
+
+	public class TSocket: IDisposable
+	{
+		private Socket socket;
+		private readonly TPoller poller;
+		private readonly SocketAsyncEventArgs innSocketAsyncEventArgs = new SocketAsyncEventArgs();
+		private readonly SocketAsyncEventArgs outSocketAsyncEventArgs = new SocketAsyncEventArgs();
+		private readonly TBuffer recvBuffer = new TBuffer();
+		private readonly TBuffer sendBuffer = new TBuffer();
+		public bool IsSending { get; private set; }
+
+		public TSocket(TPoller poller)
+		{
+			this.poller = poller;
+			this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+			this.outSocketAsyncEventArgs.Completed += this.OnComplete;
+			this.innSocketAsyncEventArgs.Completed += this.OnComplete;
+			this.IsSending = false;
+		}
+
+		public void Dispose()
+		{
+			if (this.socket == null)
+			{
+				return;
+			}
+			socket.Dispose();
+			this.socket = null;
+			poller.CanWriteSocket.Remove(this);
+		}
+
+		public void Connect(string host, int port)
+		{
+			socket.ConnectAsync(this.innSocketAsyncEventArgs);
+		}
+
+		public int CanRecvSize
+		{
+			get
+			{
+				return this.recvBuffer.Count;
+			}
+		}
+
+		public void Recv(byte[] buffer)
+		{
+			this.recvBuffer.RecvFrom(buffer);
+		}
+
+		public void Send(byte[] buffer)
+		{
+			this.sendBuffer.SendTo(buffer);
+			// 如果正在发送,则不做可发送标记
+			if (this.IsSending)
+			{
+				return;
+			}
+			if (this.poller.CanWriteSocket.Contains(this))
+			{
+				return;
+			}
+			this.poller.CanWriteSocket.Add(this);
+		}
+
+		private void OnComplete(object sender, SocketAsyncEventArgs e)
+		{
+			Action action = () => { };
+			switch (e.LastOperation)
+			{
+				case SocketAsyncOperation.Accept:
+					break;
+				case SocketAsyncOperation.Connect:
+					action = this.OnConnComplete;
+					break;
+				case SocketAsyncOperation.Disconnect:
+					break;
+				case SocketAsyncOperation.Receive:
+					action = () => this.OnRecvComplete(e.BytesTransferred);
+					break;
+				case SocketAsyncOperation.Send:
+					action = () => this.OnSendComplete(e.BytesTransferred);
+					break;
+				default:
+					throw new ArgumentOutOfRangeException();
+			}
+			TSocketState socketState = new TSocketState
+			{
+				Action = action,
+			};
+			
+			this.poller.Add(socketState);
+		}
+
+		private void OnConnComplete()
+		{
+			this.BeginRecv();
+		}
+
+		private void OnRecvComplete(int bytesTransferred)
+		{
+			this.recvBuffer.LastIndex += bytesTransferred;
+			if (this.recvBuffer.LastIndex == TBuffer.ChunkSize)
+			{
+				this.recvBuffer.LastIndex = 0;
+				this.recvBuffer.AddLast();
+			}
+			this.BeginRecv();
+		}
+
+		private void OnSendComplete(int bytesTransferred)
+		{
+			this.sendBuffer.FirstIndex += bytesTransferred;
+			if (this.sendBuffer.FirstIndex == TBuffer.ChunkSize)
+			{
+				this.sendBuffer.FirstIndex = 0;
+				this.sendBuffer.RemoveFirst();
+			}
+
+			// 如果没有数据可以发送,则返回
+			if (this.sendBuffer.Count == 0)
+			{
+				this.IsSending = false;
+				return;
+			}
+
+			// 继续发送数据
+			this.BeginSend();
+		}
+
+		private void BeginRecv()
+		{
+			this.innSocketAsyncEventArgs.SetBuffer(this.recvBuffer.Last, this.recvBuffer.LastIndex, TBuffer.ChunkSize - this.recvBuffer.LastIndex);
+			this.socket.ReceiveAsync(this.innSocketAsyncEventArgs);
+		}
+
+		public void BeginSend()
+		{
+			this.IsSending = true;
+			int count = 0;
+			if (TBuffer.ChunkSize - this.sendBuffer.FirstIndex < this.sendBuffer.Count)
+			{
+				count = TBuffer.ChunkSize - this.sendBuffer.FirstIndex;
+			}
+			else
+			{
+				count = this.sendBuffer.Count;
+			}
+			this.outSocketAsyncEventArgs.SetBuffer(this.sendBuffer.First, this.sendBuffer.FirstIndex, count);
+			this.socket.SendAsync(outSocketAsyncEventArgs);
+		}
+	}
+}

+ 0 - 72
CSharp/Platform/TNet/TcpAcceptor.cs

@@ -1,72 +0,0 @@
-using System;
-using System.Net;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-namespace TNet
-{
-	public class TcpAcceptor: IDisposable
-	{
-		private readonly Socket socket;
-		private readonly SocketAsyncEventArgs asyncEventArgs = new SocketAsyncEventArgs();
-
-		public TcpAcceptor(string ip, ushort port, int backLog = 100)
-		{
-			this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-			this.asyncEventArgs.Completed += OnArgsCompletion;
-			this.socket.Bind(new IPEndPoint(IPAddress.Parse(ip), port));
-			this.socket.Listen(backLog);
-		}
-
-		public void Dispose()
-		{
-			this.socket.Dispose();
-		}
-
-		/// <summary>
-		/// SocketAsyncEventArgs Accept回调函数,回调可能已经到了另外的线程
-		/// </summary>
-		/// <returns></returns>
-		public Task<NetworkStream> AcceptAsync()
-		{
-			var tcs = new TaskCompletionSource<NetworkStream>();
-
-			try
-			{
-				this.asyncEventArgs.UserToken = tcs;
-
-				bool ret = this.socket.AcceptAsync(this.asyncEventArgs);
-
-				if (!ret)
-				{
-					if (this.asyncEventArgs.SocketError == SocketError.Success)
-					{
-						var acceptSocket = this.asyncEventArgs.AcceptSocket;
-						this.asyncEventArgs.AcceptSocket = null;
-						return Task.FromResult(new NetworkStream(acceptSocket, true));
-					}
-					tcs.TrySetException(new InvalidOperationException(this.asyncEventArgs.SocketError.ToString()));
-				}
-			}
-			catch (Exception ex)
-			{
-				tcs.TrySetException(ex);
-			}
-			return tcs.Task;
-		}
-
-		private static void OnArgsCompletion(object sender, SocketAsyncEventArgs e)
-		{
-			var tcs = (TaskCompletionSource<NetworkStream>) e.UserToken;
-
-			if (e.SocketError != SocketError.Success)
-			{
-				tcs.TrySetException(new InvalidOperationException(e.SocketError.ToString()));
-				return;
-			}
-			var acceptSocket = e.AcceptSocket;
-			e.AcceptSocket = null;
-			tcs.SetResult(new NetworkStream(acceptSocket, true));
-		}
-	}
-}

+ 0 - 1
CSharp/Platform/TNetTest/TNetTest.csproj

@@ -51,7 +51,6 @@
     </Otherwise>
   </Choose>
   <ItemGroup>
-    <Compile Include="TcpAcceptorTest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="TcpListenerTest.cs" />
   </ItemGroup>

+ 0 - 97
CSharp/Platform/TNetTest/TcpAcceptorTest.cs

@@ -1,97 +0,0 @@
-using System;
-using System.Net.Sockets;
-using System.Threading;
-using Common.Helper;
-using Common.Logger;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using TNet;
-
-namespace TNetTest
-{
-	[TestClass]
-	public class TcpAcceptorTest
-	{
-		private const ushort port = 11111;
-		private int count;
-		private readonly Barrier barrier = new Barrier(2);
-		private readonly object lockObject = new object();
-
-		[TestMethod]
-		public void AcceptAsync()
-		{
-			var thread1 = new Thread(this.Server);
-			thread1.Start();
-
-			Thread.Sleep(2);
-
-			for (int i = 0; i < 99; ++i)
-			{
-				var thread = new Thread(this.Client);
-				thread.Start();
-			}
-			this.barrier.SignalAndWait();
-		}
-
-		private async void Client()
-		{
-			using (var tcpClient = new TcpClient(AddressFamily.InterNetwork))
-			{
-				await tcpClient.ConnectAsync("127.0.0.1", port);
-				using (NetworkStream ns = tcpClient.GetStream())
-				{
-					try
-					{
-						var bytes = "tanghai".ToByteArray();
-						for (int i = 0; i < 100000; ++i)
-						{
-							await ns.WriteAsync(bytes, 0, bytes.Length);
-							int n = await ns.ReadAsync(bytes, 0, bytes.Length);
-							Assert.AreEqual(7, n);
-						}
-					}
-					catch (Exception e)
-					{
-						Log.Debug(e.ToString());
-					}
-				}
-			}
-			this.barrier.RemoveParticipants(1);
-		}
-
-		private async void Server()
-		{
-			using (var tcpAcceptor = new TcpAcceptor("127.0.0.1", port))
-			{
-				while (this.count != 99)
-				{
-					Log.Debug("start server response");
-					NetworkStream ns = await tcpAcceptor.AcceptAsync();
-					// 这里可能已经不在Server函数线程了
-					Log.Debug("server response");
-					this.Response(ns);
-				}
-			}
-		}
-
-		private async void Response(NetworkStream ns)
-		{
-			try
-			{
-				var bytes = new byte[1000];
-				for (int i = 0; i < 100000; ++i)
-				{
-					int n = await ns.ReadAsync(bytes, 0, 100);
-					await ns.WriteAsync(bytes, 0, n);
-				}
-				lock (this.lockObject)
-				{
-					++this.count;
-				}
-			}
-			catch (Exception e)
-			{
-				Log.Debug(e.ToString());
-			}
-		}
-	}
-}