Parcourir la source

修复websocket的bug,websocket recv是协程,在收的时候,同一个channel有可能要写,所以要分开用两个MemoryStream

tanghai il y a 7 ans
Parent
commit
6a5bd3db94

+ 8 - 4
Unity/Assets/Model/Module/Message/Network/WebSocket/WChannel.cs

@@ -20,6 +20,8 @@ namespace ETModel
 
 
         private readonly MemoryStream memoryStream;
         private readonly MemoryStream memoryStream;
 
 
+        private readonly MemoryStream recvStream;
+
         private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
         private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
         
         
         public WChannel(HttpListenerWebSocketContext webSocketContext, AService service): base(service, ChannelType.Accept)
         public WChannel(HttpListenerWebSocketContext webSocketContext, AService service): base(service, ChannelType.Accept)
@@ -31,6 +33,7 @@ namespace ETModel
             this.webSocket = webSocketContext.WebSocket;
             this.webSocket = webSocketContext.WebSocket;
             
             
             this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
             this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
+            this.recvStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
 
 
             isConnected = true;
             isConnected = true;
         }
         }
@@ -42,6 +45,7 @@ namespace ETModel
             this.webSocket = webSocket;
             this.webSocket = webSocket;
             
             
             this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
             this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
+            this.recvStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
 
 
             isConnected = false;
             isConnected = false;
         }
         }
@@ -173,9 +177,9 @@ namespace ETModel
                     try
                     try
                     {
                     {
 #if SERVER
 #if SERVER
-                        ValueWebSocketReceiveResult receiveResult = await this.webSocket.ReceiveAsync(new Memory<byte>(this.Stream.GetBuffer(), 0, this.Stream.Capacity), cancellationTokenSource.Token);
+                        ValueWebSocketReceiveResult receiveResult = await this.webSocket.ReceiveAsync(new Memory<byte>(this.recvStream.GetBuffer(), 0, this.recvStream.Capacity), cancellationTokenSource.Token);
 #else
 #else
-                        WebSocketReceiveResult receiveResult = await this.webSocket.ReceiveAsync(new ArraySegment<byte>(this.Stream.GetBuffer(), 0, this.Stream.Capacity), cancellationTokenSource.Token);
+                        WebSocketReceiveResult receiveResult = await this.webSocket.ReceiveAsync(new ArraySegment<byte>(this.recvStream.GetBuffer(), 0, this.recvStream.Capacity), cancellationTokenSource.Token);
 #endif
 #endif
                         
                         
                         if (this.IsDisposed)
                         if (this.IsDisposed)
@@ -195,8 +199,8 @@ namespace ETModel
                             return;
                             return;
                         }
                         }
                         
                         
-                        this.Stream.SetLength(receiveResult.Count);
-                        this.OnRead(this.Stream);
+                        this.recvStream.SetLength(receiveResult.Count);
+                        this.OnRead(this.recvStream);
                     }
                     }
                     catch (Exception)
                     catch (Exception)
                     {
                     {

+ 0 - 1
Unity/Unity.Editor.csproj

@@ -70,7 +70,6 @@
     <Compile Include="Assets\Editor\RsyncEditor\RsyncEditor.cs" />
     <Compile Include="Assets\Editor\RsyncEditor\RsyncEditor.cs" />
     <Compile Include="Assets\Editor\ServerCommandLineEditor\ServerCommandLineEditor.cs" />
     <Compile Include="Assets\Editor\ServerCommandLineEditor\ServerCommandLineEditor.cs" />
     <Compile Include="Assets\Editor\ServerManagerEditor\ServerManagerEditor.cs" />
     <Compile Include="Assets\Editor\ServerManagerEditor\ServerManagerEditor.cs" />
-    <None Include="Assets\Editor\Unity.Editor.asmdef" />
     <Reference Include="UnityEngine.CoreModule">
     <Reference Include="UnityEngine.CoreModule">
       <HintPath>C:/Apps/Unity2017/Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
       <HintPath>C:/Apps/Unity2017/Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
     </Reference>
     </Reference>

+ 0 - 1
Unity/Unity.Hotfix.csproj

@@ -113,7 +113,6 @@
     <Compile Include="Assets\Hotfix\UI\UILogin\Component\UILoginComponent.cs" />
     <Compile Include="Assets\Hotfix\UI\UILogin\Component\UILoginComponent.cs" />
     <Compile Include="Assets\Hotfix\UI\UILogin\Event\InitSceneStart_CreateLoginUI.cs" />
     <Compile Include="Assets\Hotfix\UI\UILogin\Event\InitSceneStart_CreateLoginUI.cs" />
     <Compile Include="Assets\Hotfix\UI\UILogin\Factory\UILoginFactory.cs" />
     <Compile Include="Assets\Hotfix\UI\UILogin\Factory\UILoginFactory.cs" />
-    <None Include="Assets\Hotfix\Unity.Hotfix.asmdef" />
     <Reference Include="UnityEngine.CoreModule">
     <Reference Include="UnityEngine.CoreModule">
       <HintPath>C:/Apps/Unity2017/Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
       <HintPath>C:/Apps/Unity2017/Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
     </Reference>
     </Reference>

+ 0 - 1
Unity/Unity.Model.csproj

@@ -354,7 +354,6 @@
     <Compile Include="Assets\Model\UI\UILoading\Event\LoadingBeginEvent_CreateLoadingUI.cs" />
     <Compile Include="Assets\Model\UI\UILoading\Event\LoadingBeginEvent_CreateLoadingUI.cs" />
     <Compile Include="Assets\Model\UI\UILoading\Event\LoadingFinishEvent_RemoveLoadingUI.cs" />
     <Compile Include="Assets\Model\UI\UILoading\Event\LoadingFinishEvent_RemoveLoadingUI.cs" />
     <Compile Include="Assets\Model\UI\UILoading\Factory\UILoadingFactory.cs" />
     <Compile Include="Assets\Model\UI\UILoading\Factory\UILoadingFactory.cs" />
-    <None Include="Assets\Model\Unity.Model.asmdef" />
     <Reference Include="UnityEngine.CoreModule">
     <Reference Include="UnityEngine.CoreModule">
       <HintPath>C:/Apps/Unity2017/Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
       <HintPath>C:/Apps/Unity2017/Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
     </Reference>
     </Reference>

+ 0 - 1
Unity/Unity.ThirdParty.csproj

@@ -631,7 +631,6 @@
     <Compile Include="Assets\ThirdParty\MongoDB\MongoDB.Shared\CanonicalEquatableStruct.cs" />
     <Compile Include="Assets\ThirdParty\MongoDB\MongoDB.Shared\CanonicalEquatableStruct.cs" />
     <Compile Include="Assets\ThirdParty\MongoDB\MongoDB.Shared\Hasher.cs" />
     <Compile Include="Assets\ThirdParty\MongoDB\MongoDB.Shared\Hasher.cs" />
     <Compile Include="Assets\ThirdParty\MongoDB\MongoDB.Shared\IncrementalMD5.cs" />
     <Compile Include="Assets\ThirdParty\MongoDB\MongoDB.Shared\IncrementalMD5.cs" />
-    <None Include="Assets\ThirdParty\Unity.ThirdParty.asmdef" />
     <Reference Include="UnityEngine.CoreModule">
     <Reference Include="UnityEngine.CoreModule">
       <HintPath>C:/Apps/Unity2017/Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
       <HintPath>C:/Apps/Unity2017/Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll</HintPath>
     </Reference>
     </Reference>