Procházet zdrojové kódy

enet mtu 改成512,启用crc校验

tanghai před 11 roky
rodič
revize
4f37269fdf

+ 1 - 1
CSharp/Platform/ENet/enet.h

@@ -208,7 +208,7 @@ enum
    ENET_HOST_RECEIVE_BUFFER_SIZE          = 256 * 1024,
    ENET_HOST_SEND_BUFFER_SIZE             = 256 * 1024,
    ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL  = 1000,
-   ENET_HOST_DEFAULT_MTU                  = 1400,
+   ENET_HOST_DEFAULT_MTU                  = 512,
    ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE  = 32 * 1024 * 1024,
    ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA = 32 * 1024 * 1024,
 

+ 1 - 0
CSharp/Platform/ENet/host.cc

@@ -102,6 +102,7 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
     host -> duplicatePeers = ENET_PROTOCOL_MAXIMUM_PEER_ID;
     host -> maximumPacketSize = ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE;
     host -> maximumWaitingData = ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA;
+	host->checksum = enet_crc32;
 
     host -> compressor.context = NULL;
     host -> compressor.compress = NULL;

+ 1 - 6
CSharp/Platform/UNet/EService.cs

@@ -89,11 +89,6 @@ namespace UNet
 			}
 		}
 
-		public void EnableCrc()
-		{
-			NativeMethods.EnetEnableCrc(this.host);
-		}
-
 		private EEvent GetEvent()
 		{
 			var enetEv = new ENetEvent();
@@ -102,7 +97,7 @@ namespace UNet
 			{
 				return null;
 			}
-			var e = new EEvent(enetEv);
+			EEvent e = new EEvent(enetEv);
 			return e;
 		}
 

+ 0 - 3
CSharp/Platform/UNet/NativeMethods.cs

@@ -44,9 +44,6 @@ namespace UNet
 				EntryPoint = "enet_initialize_with_callbacks")]
 		internal static extern int EnetInitializeWithCallbacks(uint version, ref ENetCallbacks inits);
 
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_enable_crc")]
-		internal static extern void EnetEnableCrc(IntPtr host);
-
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_create")]
 		internal static extern IntPtr EnetHostCreate(
 				ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth,

+ 6 - 5
CSharp/Platform/UNet/USocket.cs

@@ -52,7 +52,8 @@ namespace UNet
 				{
 					return new ENetPeer();
 				}
-				return (ENetPeer) Marshal.PtrToStructure(this.peerPtr, typeof (ENetPeer));
+				ENetPeer peer = (ENetPeer) Marshal.PtrToStructure(this.peerPtr, typeof (ENetPeer));
+				return peer;
 			}
 			set
 			{
@@ -175,11 +176,11 @@ namespace UNet
 			// 如果有缓存的包,从缓存中取
 			if (this.recvBuffer.Count > 0)
 			{
-				var bytes = this.recvBuffer.First.Value;
+				byte[] bytes = this.recvBuffer.First.Value;
 				this.recvBuffer.RemoveFirst();
 				tcs.TrySetResult(bytes);
 			}
-					// 没有缓存封包,设置回调等待
+			// 没有缓存封包,设置回调等待
 			else
 			{
 				this.Received = eEvent =>
@@ -189,9 +190,9 @@ namespace UNet
 						tcs.TrySetException(new EException("socket disconnected in receive"));
 					}
 
-					using (var packet = new EPacket(eEvent.PacketPtr))
+					using (EPacket packet = new EPacket(eEvent.PacketPtr))
 					{
-						var bytes = packet.Bytes;
+						byte[] bytes = packet.Bytes;
 						tcs.TrySetResult(bytes);
 					}
 				};

+ 1 - 1
CSharp/Platform/UNetExe/Program.cs

@@ -6,7 +6,7 @@ namespace ENetExe
 	{
 		private static void Main(string[] args)
 		{
-			var test = new UNetClientServerTest();
+			var test = new UServiceTest();
 			test.ClientSendToServer();
 		}
 	}

+ 1 - 1
CSharp/Platform/UNetTest/UNetTest.csproj

@@ -54,7 +54,7 @@
     </Otherwise>
   </Choose>
   <ItemGroup>
-    <Compile Include="UNetClientServerTest.cs" />
+    <Compile Include="UServiceTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Common\Common.csproj">

+ 1 - 1
CSharp/Platform/UNetTest/UNetClientServerTest.cs → CSharp/Platform/UNetTest/UServiceTest.cs

@@ -9,7 +9,7 @@ using Network;
 namespace UNetTest
 {
 	[TestClass]
-	public class UNetClientServerTest
+	public class UServiceTest
 	{
 		private readonly Barrier barrier = new Barrier(3);